使用基于 XML 模式的配置时不考虑 Spring 配置文件



我想在integration spring配置文件未激活时使用弹簧豆初始化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 似乎完全忽略了 <beans> 标签,即使配置文件是默认的。即使删除 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>

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

好的,似乎无论如何都没有初始化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>

最新更新