2017-07-24 144 views
0

这里是我的情况:如何设置默认配置文件春天

a.xml 
----- 
<beans> <!-- no 'profile' attribute --> 
    <bean id="a" class="com.a.A"/> 
</beans> 

b.xml 
----- 
<beans > <!-- no 'profile' attribute --> 
    <bean id="b" class="com.b.B"/> 
</beans> 

c.xml 
----- 
<beans ><!-- no 'profile' attribute --> 
    <bean id="c" class="com.c.C"/> 
</beans> 

<beans profile="dev"> 
    <rabbit:connection-factory id="connectionFactory" 
    host="x.x.net" username="a" port="xxxx" 
    password="a" /> 

    .... 
    .... 

</beans> 

目的

  1. 当我在本地运行我的应用程序,我想从A.XML加载所有豆类, b.xml和C.xml中的所有bean,除了配置文件“dev”

  2. 当我在开发环境中运行我的应用程序时,我想从a.xml,b.xml和C.xml中的所有bean中加载所有bean

我将-Dspring.profiles.active =!dev设置为JVM系统参数。问题是它没有加载其他bean。

任何想法,我该如何处理这种情况?

回答

0

这应该是你期望的行为,没有任何配置文件根本在本地传入(等待导入所有3个xml文件)。带有“dev”的beans元素只有在使用dev配置文件启动spring时才会加载。

+0

谢谢,@LetsBeFrank。 1.它将加载a,b,c.xml中的所有bean,除非在本地如果我没有传递任何配置文件,那么在本地标记为“dev”的那个bean除外。 2.它加载了a,b,c.xml中的所有bean,包括当我通过时标记为“dev”的bean:-Dspring.profiles.active = dev,default – Suman