3

要阅读我使用的 Spring 配置文件:

<beans profile="LOC">

我将此属性设置为 jvm 属性:

-Dspring.profiles.active=LOC

是否可以使用某些逻辑只使用配置文件“LOC”,如果它存在并且它不存在使用默认配置文件?

4

2 回答 2

3

这在 spring 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

于 2013-07-25T20:25:23.077 回答
1

如果你有一个 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

这对你来说足够了吗?

于 2013-07-25T19:05:43.260 回答