没有从context.xml文件中的属性文件获取值

 zhaoxiao2012_549 发布于 2023-02-04 20:33

我无法从.properties文件中检索到我的值context.xml

pom.xml(没有提到依赖项)


    4.0.0


    com
    myproj
    0.1.1
    war

    myproj
    http://maven.apache.org

    
        
            dev
            
                true
            
            
                dev
                0
                0
            
        

    

    
        
            
                src/main/resources
                false

            
            
                src/main/environment
                false

            
        

        
            
                org.codehaus.mojo
                tomcat-maven-plugin
                1.0-alpha-2
            

            
                org.apache.maven.plugins
                maven-resources-plugin
                2.5
                
                    UTF-8
                
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                2.8
                
                    false
                    true
                    
                        **/*_Roo_*
                    
                
            
            
                org.apache.maven.plugins
                maven-assembly-plugin
                2.2.1
                
                    
                        jar-with-dependencies
                    
                
            
            
                org.apache.maven.plugins
                maven-eclipse-plugin
                2.7
                
                    true
                    false
                    2.0
                    
                        
                            org.eclipse.ajdt.core.ajbuilder
                            
                                org.springframework.aspects
                            
                        
                        
                            org.springframework.ide.eclipse.core.springbuilder
                        
                    
                    
                        org.eclipse.ajdt.ui.ajnature
                        com.springsource.sts.roo.core.nature
                        org.springframework.ide.eclipse.core.springnature
                    
                
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                2.0.2
                
                    1.7
                    1.7
                
            
            
                org.apache.maven.plugins
                maven-war-plugin
                2.3
                
                    myproj
                
            
        
    




context.xml(在src/main/webapp/META-INF中)




 


我在.properties里面有一些文件:

src/main/resources
src/main/environment/dev

我无法在$ {database.usernameee}$ {database.password}的 context.xml中获取值

请说明出了什么问题?

1 个回答
  • 请执行下列操作:

    1)删除该<resources>部分.您不想进行过滤,这src/main/resources是默认设置 - 不需要单独指定.

    <build>
        <!-- Delete the <resources> section -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
    
            </resource>
            <resource>
                <directory>src/main/environment</directory>
                <filtering>false</filtering>
    
            </resource>
        </resources>
    

    2)<filters><build>指定环境特定属性文件下添加元素

    <build>
        <filters>
            <filter>src/main/environment/${env}/some.properties</filter>
        </filters>
        ...
    

    以上假设您的属性文件被调用some.properties- 因此将其更改为文件的真实名称.

    3)修改配置 maven-war-plugin

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
            <webResources>
                <resource>
                    <filtering>true</filtering>
                    <directory>src/main/webapp</directory>
                    <includes>
                        <include>**/META-INF/context.xml</include>
                    </includes>
                </resource>
            </webResources>
            <warSourceDirectory>src/main/webapp</warSourceDirectory>
            <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
            <warName>myproj</warName>
        </configuration>
    </plugin>
    

    现在,这将过滤context.xml使用特定于环境的属性 - 具体取决于您使用的配置文件.

    (请注意,'database.usernameee'中可能有拼写错误 - 因为它最后有额外的ee)

    2023-02-04 20:36 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有