2013-04-15 79 views
0

我想要做一个SPRING(3.2.1)设置,在那里我可以根据你所处的环境来切换底层的JMS提供者。 dev,test,prod。我不是专家,但已经遇到了Spring的@Profile注释。我真的不知道如何使用它。所以我需要做的是在DEV环境中我想使用ActiveMQ,而在PRODUCTION中我想使用IBM MQ。这可能吗?如果是这样,将不胜感激,如果你可以提供一些配置或代码来做到这一点。提前致谢。在jms提供者之间切换

回答

0

http://static.springsource.org/spring-framework/docs/3.2.1.RELEASE/spring-framework-reference/html/new-in-3.1.html#new-in-3.1-bean-definition-profiles

对于XML配置,请参阅本博客... http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/

看到这个博客约@profile:http://blog.springsource.com/2011/02/14/spring-3-1-m1-introducing-profile/使用型材@Configuration。

它归结为...

当使用XML配置,只需在Spring配置文件的末尾添加<beans/>元素...

<beans ...> 
    <bean... /> 

    <beans profile="DEV"> 
     <bean ... // my ActiveMQ config .../> 
    </beans? 

    <beans profile="default"> 
     <bean ... // my IBM (or JNDI) config .../> 
    <beans/> 
</beans> 

然后在开发中与-Dspring-profiles-active=DEV运行。

类似地@Profile可以添加到@Configuration类中,以限制它们对特定活动配置文件的使用。

+0

感谢您的查询答复。我会试试这个并回传。再次感谢。 – user2279337