繁体   English   中英

通过web.xml中的ContextLoaderListener初始化spring bean配置文件

[英]Initialize spring bean profile through ContextLoaderListener in web.xml

在我的web.xml我正在声明一个ContextLoaderListener来以这种方式配置spring应用程序:

<listener>    
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    
</listener>

在我的一个spring配置xml文件中,我使用不同的bean配置文件进行开发和生产。

<beans profile="production">
   <bean />
</beans
<beans profile="development">
   <bean />
</beans

我如何在web.xml设置默认的bean配置文件? 使用ContextLoaderListener而不是spring servlet时,有类似的内容:

<init-param>
   <param-name>spring.profiles.active</param-name>
   <param-value>production</param-value>
</init-param>

您可以在ContextLoaderListener级别配置web.xml

<context-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>profileName</param-value>
</context-param>

DispatcherServlet的级别:

<init-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>profileName</param-value>
</init-param>

参考: http//spring.io/blog/2011/02/11/spring-framework-3-1-m1-released/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM