简体   繁体   English

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

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

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 profile for 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 ? 我如何在web.xml设置默认的bean配置文件? is there something similar to the following when using ContextLoaderListener instead of spring servlet: 使用ContextLoaderListener而不是spring servlet时,有类似的内容:

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

You can configure web.xml at the level of ContextLoaderListener with: 您可以在ContextLoaderListener级别配置web.xml

<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/

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

相关问题 无法通过web.xml中的ContextLoaderListener初始化spring - Unable to initialize spring through ContextLoaderListener in web.xml 将ContextLoaderListener添加到Spring MVC中的web.xml - Adding ContextLoaderListener to web.xml in Spring MVC Spring-MVC web.xml 文件不使用 ContextLoaderListener - Spring-MVC web.xml file not using ContextLoaderListener 即使web.xml不包含Spring的ContextLoaderListener,该如何运行呢? - How is ContextLoaderListener from Spring being run even when web.xml does not include it? 在没有web.xml文件的Tomcat Web应用程序中设置Spring配置文件 - Set Spring profile in Tomcat web app with no web.xml file 如何在Web.xml中添加dispatcherServlet等Spring Bean配置 - How to add dispatcherServlet and other Spring Bean configuration in Web.xml 在web.xml中添加ContextLoaderListener和RequestContextListener时找不到资源(404) - Resource not found(404) when adding ContextLoaderListener and RequestContextListener in web.xml spring web,security + web.xml + mvc dispatcher + Bean创建两次 - spring web, security + web.xml + mvc dispatcher + Bean is created twice 基于Maven配置文件的web.xml配置 - web.xml configuration based on Maven profile Spring contextloaderlistener在bean创建中的作用 - Spring contextloaderlistener role in bean creation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM