【问题标题】:Spring Integration with Multiple configuration filesSpring 与多个配置文件的集成
【发布时间】:2013-10-22 04:50:37
【问题描述】:

我有一个带有多个配置文件的 Spring Integration 应用程序,每个配置文件都连接到一个 JMS 队列。所有队列都将消息发送到单个通道 [requestChannel],我将这些公共信息保存在 common.xml 文件中。

当我向 JMS 队列发送消息时,只有一个队列正在发送消息 requestChannel,其余队列没有向目标 [requestChannel] 发送消息。

有人可以建议我做错了什么。

我可以在 2 个不同的文件中使用相同的变量名称并在一个主 Conext 文件中调用它们吗? [MainApplicationContext.xml],目前我正在做这个。

MainApplicationContext.xml 文件——调用所有其他配置文件。

<beans>
<import resource="common.xml"/> 
<import resource="config1.xml"/> 
<import resource="config2.xml"/>
<import resource="config3.xml"/>
</beans>

Common.xml -- 有公共频道详情

<bean>
<int:channel id="requestChannel" />

<bean id="testBean" class="com.TestBean" />

<int:chain input-channel="requestChannel">
    <int:service-activator ref="testBean" method="processor"/>
</int:chain>    

<int:channel id="errorChannel" />
<bean id="epBean" class="com.ErrorProcessorBean" />

<int:chain input-channel="errorChannel">
    <int:service-activator ref="epBean" method="processor"/>
</int:chain>    

</bean>

config1.xml -- JMS 队列 1

<beans>

    <int-jms:message-driven-channel-adapter
    id="jmsInputQueueAdaptor_au"  channel="requestChannel" connection-factory="cf_au"  destination="InputQueueOne"
    error-channel="errorChannel" />

    <jee:jndi-lookup id="cf_au" jndi-name="jms/ConnectionFactory">  
    </jee:jndi-lookup>

    <jee:jndi-lookup id="InputQueueOne" jndi-name="jms/InputQueueOne">      
    </jee:jndi-lookup>

</beans>

config2.xml -- JMS 队列 2

<beans>

    <int-jms:message-driven-channel-adapter
    id="jmsInputQueueAdaptor_au"  channel="requestChannel" connection-factory="cf_au"  destination="InputQueueOne"
    error-channel="errorChannel" />

    <jee:jndi-lookup id="cf_au" jndi-name="jms/ConnectionFactory">  
    </jee:jndi-lookup>

    <jee:jndi-lookup id="InputQueueTwo" jndi-name="jms/InputQueueTwo">      
    </jee:jndi-lookup>

</beans>

【问题讨论】:

    标签: spring jms integration


    【解决方案1】:

    Bean ID 在 bean 上下文中应该是唯一的。有多种方法可以创建具有父/子关系的多个上下文,这可能是您所期望的,但“导入”不会这样做。所以 config2.xml 中定义的 id="jsmInputQueueAdapter_au" 的 bean 替换了之前在 config1.xml 中定义的 id 的 bean。

    此外,在您的示例中,两个 bean 具有相同的属性,包括 destination="InputQueueOne"。

    更新:作为创建 bean 上下文的父子层次结构的示例,请参阅 Spring contexts hierarchy

    【讨论】:

    • 您好,请您详细说明如何在spring中创建具有父子关系的多个配置文件。
    猜你喜欢
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    • 2013-12-31
    相关资源
    最近更新 更多