我想在integration
弹簧配置文件未激活时使用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似乎完全忽略了<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>
然而,这会失去豆类分析。我能做错什么?
答案 0 :(得分:0)
好吧,似乎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>