【问题标题】:Spring profiles and Spring Integration namespacesSpring 配置文件和 Spring Integration 命名空间
【发布时间】:2015-10-08 07:17:03
【问题描述】:

我正在尝试创建以下 spring 配置

<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 id 异常...

知道为什么吗?

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

【问题讨论】:

  • 你能发布异常堆栈跟踪吗?

标签: spring spring-integration


【解决方案1】:

您必须为当前上下文提供活动配置文件。该令牌可以设置为:
环境变量
JVM 属性
网页参数
程序化
Spring 还会查找令牌 spring.profiles.default,如果没有使用 spring.profiles.active 指定,则可以使用该令牌设置默认配置文件。

例子:

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

【讨论】:

  • 嗯,我见过类似的东西,但在我的情况下是 ActiveMQ 模式,例如org.springframework.web.context.ContextLoader:上下文初始化失败 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自类路径资源 [au/gov/dha/messagecentre/messagecentre-jms.xml] 的 XML 文档中的第 179 行是无效的;嵌套异常是 org.xml.sax.SAXParseException;行号:179;列号:129; cvc-id.2:ID 值“messageCentreBroker”多次出现。这是使用 amq: schema inside beans:
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    相关资源
    最近更新 更多