【问题标题】:Initialize spring bean profile through ContextLoaderListener in web.xml通过web.xml中的ContextLoaderListener初始化spring bean profile
【发布时间】:2014-03-01 17:23:38
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: java spring web.xml servlet-listeners spring-bean


    【解决方案1】:

    您可以在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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-02
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多