3

在我web.xml的声明中,我ContextLoaderListener以这种方式配置 spring 应用程序:

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

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

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

我如何在 ? 中设置默认 bean 配置文件web.xmlContextLoaderListener使用而不是spring servlet时是否有类似以下内容:

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

1 回答 1

12

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

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

于 2014-02-05T10:38:40.627 回答