我对PropertyPlaceholderConfigurer(org.springframework.beans.factory.config.PropertyPlaceholderConfigurer)和我的pom.xml中定义的普通筛选器之间的区别有疑问。PropertyPlaceholderConfigurer vs筛选器 - Spring豆豆
我一直在看示例,它看起来即使过滤器被定义并标记为在pom.xml中默认激活,但他们仍然使用Spring的applicationContext.xml中的PropertyPlaceholderConfigurer。
这意味着pom.xml引用了filter-LOCAL.properties,而applicationContext.xml引用了application.properties并且它们都包含相同的设置。
这是为什么?这是应该如何完成的?我能够运行目标mvn jetty:运行时不存在application.properties,但是如果我将设置添加到与filter-LOCAL.properties不同的application.properties,它们似乎不会被覆盖。
这里是我的意思的例子:
的pom.xml
<profiles> <profile> <id>LOCAL <activation> <activeByDefault>true </activation> <properties> <env>LOCAL </properties> </profile> </profiles>
的applicationContext.xml
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:application.properties </list> </property> <property name="ignoreResourceNotFound" value="true"/> </bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean>
application.properties的内容的一个例子和filters-LOCAL.properties
jdbc.driver=org.postgresql.Driver jdbc.url=jdbc:postgresql://localhost/shoutbox_dev jdbc.username=tester jdbc.password=tester
我可以从ApplicationContext中删除propertyConfigurer,创建PROD过滤器和无视application.properties文件,或意志给部署到生产服务器时,我发出?
你有什么我应该谷歌找出如何使用Maven按照你的建议选择弹簧属性的建议吗? – John 2010-05-03 11:46:47
@John:就个人而言,我更喜欢Ivy和Ant,但校长应该是一样的。取决于我为哪个环境构建,我复制不同的属性文件并将其重命名为例如application.properties。然后,我导入PropertyPlaceholderConfigurer的Spring应用程序上下文仅知道application.properties。如果这是从test.properties复制的,或者production.properties对于Spring容器是未知的。只有我的测试上下文知道我的JUnit测试的测试属性。 – Espen 2010-05-03 11:52:30
-1 - 为每个环境构建可部署的单独实例是个不错的主意。它不能很好地扩展,你最终必须破解公开的战争,以查看哪些属性包含在内。看到我的答案在这里的另一种方法:http://stackoverflow.com/questions/1311360/property-placeholder-location-from-another-property/1312341#1312341 – Pablojim 2010-05-03 18:44:57