如何设置默认配置文件 Spring

How to set Default Profile Spring

这是我的场景:

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>

Objective:

  1. 当我在本地 运行 我的应用程序时,我想加载来自 a.xml、b.xml 的所有 beans 和来自 C.xml 的所有 beans 除了简介 "dev"

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

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

知道吗,我该如何处理这种情况?

这应该如您预期的那样运行,在本地期间根本没有传递任何配置文件(等待您导入所有 3 个 xml 文件)。带有 "dev" 的 beans 元素只会在 spring 使用 dev 配置文件启动时加载。