1

我正在尝试创建以下弹簧配置

<beans profile="profile1">
    <jms:outbound-channel-adapter id="sampleId"/>
</beans>

<beans profile="profile2">
    <jms:outbound-channel-adapter id="sampleId"/>
</beans>

(jms:outbound-channel-adapter 是来自 spring 集成的命名空间)

当创建这样的上下文时,我得到重复的 bean ids 异常......

知道为什么吗?

编辑..(活动配置文件设置为 profile1)

4

2 回答 2

0

您必须为当前上下文提供活动配置文件。此标记可以设置为:
环境变量
JVM 属性
Web 参数
编程
Spring 还查找标记 spring.profiles.default,如果没有使用 spring.profiles 指定,则可以使用该标记设置默认配置文件。积极的。

例子:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    <param-name>spring.profiles.active</param-name>
    <param-value>web-dev</param-value>
    </init-param>
</servlet>

其中 applicationContext 看起来像:

<beans profile="web-dev, test-dev">
        <import resource="trace-context.xml"/>
        <import resource="spring-data-jpa.xml"/>
        <import resource="spring-security-roles.xml" />
    </beans>

    <beans profile="web-dev">
        <bean id="deployProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"
                p:location="/WEB-INF/spring.properties" />

        <import resource="spring-cache.xml"/>
        <import resource="tiles-context.xml" />
        <import resource="themes-context.xml" />
    </beans>  

    <beans profile="test-dev">
        <bean id="deployProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"
                p:location="classpath:spring.properties" />
    </beans>
于 2012-10-01T08:54:27.683 回答
0

确保所有相关的 xsd 声明都使用 >= 3.1 版本。配置文件功能是在 Spring 3.1 版中添加的。至少为 beans 和 jms 命名空间设置。另请参阅我对类似 SO 问题的回答

于 2015-10-07T23:17:03.867 回答