我无法从.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 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)删除该<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)