【问题标题】:Spring profiles not taken into account when using XML schema-based configuration使用基于 XML 模式的配置时未考虑 Spring 配置文件
【发布时间】:2016-04-23 16:24:32
【问题描述】:

integration spring 配置文件不活动时,我想使用 spring bean 初始化一个 ActiveMQ 代理。我只想在默认配置文件中启动代理。设置是这样的:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
....
<beans profile="!integration">
    <!-- ** Standalone ActiveMQ server ** -->
    <amq:broker useJmx="false" persistent="false">
        <amq:transportConnectors>
            <amq:transportConnector uri="tcp://localhost:61616"/>
        </amq:transportConnectors>
    </amq:broker>
</beans>
</beans>

Spring 似乎完全忽略了&lt;beans&gt; 标签,即使配置文件是默认的。即使删除 profile=!integration 属性也不能修复 pb。

如果我将初始化 bean 的代理移动到 beans 标记之外,它工作得很好,如下所示:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!-- ** Standalone ActiveMQ server ** -->
    <amq:broker useJmx="false" persistent="false">
        <amq:transportConnectors>
            <amq:transportConnector uri="tcp://localhost:61616"/>
        </amq:transportConnectors>
    </amq:broker>
</beans>

但是,这会丢失 bean 分析。我可能做错了什么?

【问题讨论】:

    标签: spring jms activemq spring-jms spring-bean


    【解决方案1】:

    好吧,看来amq:broker无论如何都没有初始化。我发现的解决方法是将 amq:broker 包装在自定义 bean 中,如下所示:

     <beans profile="!integration">
      <bean id="embeddedJmsServerWrapper" class="eterra.ca.xinterface.common.EmbeddedActiveMQServer">
            <property name="server">
                <amq:broker useJmx="false" persistent="false">
                    <amq:transportConnectors>
                        <amq:transportConnector uri="tcp://localhost:61616"/>
                    </amq:transportConnectors>
                </amq:broker>
            </property>
        </bean>
    </bean>
    

    【讨论】:

      猜你喜欢
      • 2012-09-30
      • 1970-01-01
      • 2013-03-13
      • 2018-01-26
      • 1970-01-01
      • 2014-09-25
      • 2012-02-01
      • 2021-02-15
      • 1970-01-01
      相关资源
      最近更新 更多