要读取一个Spring配置文件我用:默认弹簧配置文件?
<beans profile="LOC">
我有这个属性设置为JVM属性:
-Dspring.profiles.active=LOC
是否有可能使用一些逻辑只是使用的配置文件“LOC”,如果它存在并且不存在使用默认配置文件?
要读取一个Spring配置文件我用:默认弹簧配置文件?
<beans profile="LOC">
我有这个属性设置为JVM属性:
-Dspring.profiles.active=LOC
是否有可能使用一些逻辑只是使用的配置文件“LOC”,如果它存在并且不存在使用默认配置文件?
如果你有一个web.xml,你可以有指定:
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>LOC</param-value>
</context-param>
否则,你可以尝试使用org.springframework.context.ApplicationContextInitializer
。请参阅:http://blog.chariotsolutions.com/2012/01/spring-31-cool-new-features.html
这对您来说足够吗?
这是可能在春季3.2,其中!运营商已推出:
<beans profile="LOC">
<import resource="LOC.xml"/>
</beans>
<beans profile="!LOC">
<import resource="default.xml"/>
</beans>
当LOC配置文件处于活动状态时,将包含LOC.xml。如果未定义LOC,则会包含default.xml。
的变化已经在这里宣布:http://www.springsource.org/node/3563
和承诺是在这里:https://github.com/SpringSource/spring-framework/commit/bcd44f3798ed06c0704d2a3564b8a9735e747e87
您可能要改一下你的问题。 “如果使用配置文件”LOC“,并且它不存在,那么使用默认配置文件是什么?”意思?你想在LOC配置文件中包含新的bean,在'默认'配置文件中覆盖bean还是其他的? –