Java 通过 web.xml 中的 ContextLoaderListener 初始化 spring bean profile
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21574551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Initialize spring bean profile through ContextLoaderListener in web.xml
提问by bachr
In my web.xml
I'm declaring a ContextLoaderListener
to configure spring application this way:
在我的web.xml
声明中,我ContextLoaderListener
以这种方式配置 spring 应用程序:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
In one of my spring configuration xml files, I'm using different beans profilefor development and production.
在我的一个 spring 配置 xml 文件中,我使用不同的bean 配置文件进行开发和生产。
<beans profile="production">
<bean />
</beans
<beans profile="development">
<bean />
</beans
How I could set the default beans profile in the web.xml
? is there something similar to the following when using ContextLoaderListener
instead of spring servlet:
我如何在web.xml
? 使用ContextLoaderListener
代替spring servlet时是否有类似以下内容:
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>production</param-value>
</init-param>
采纳答案by nobeh
You can configure web.xml
at the level of ContextLoaderListener
with:
您可以web.xml
在以下级别进行配置ContextLoaderListener
:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>profileName</param-value>
</context-param>
and the level of DispatcherServlet
with:
和水平DispatcherServlet
:
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>profileName</param-value>
</init-param>
Reference: http://spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/
参考:http: //spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/