Initialize the spring bean profile via ContextLoaderListener in web.xml

In mine, web.xmlI declare ContextLoaderListenerto configure the spring application as follows:

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

In one of my spring xml configuration files, I use a different beans profile for development and production.

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

How can I set beans default profile in web.xml? is there something similar to the following when used ContextLoaderListenerinstead of spring servlet:

<init-param>
   <param-name>spring.profiles.active</param-name>
   <param-value>production</param-value>
</init-param>
+3
source share
1 answer

You can adjust web.xmlat a level ContextLoaderListenerwith:

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

and level DispatcherServletc:

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

+12

All Articles