2013-10-14 71 views
1

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

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

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

我可以在两个不同的文件中使用相同的varibale名称并在一个主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> 

回答

4

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

另外,在您的示例中,两个bean都具有相同的属性,包括destination =“InputQueueOne”。

更新:作为创建豆上下文的父子层次结构的一个例子,看到 Spring contexts hierarchy

+0

嗨能否请您详细阐述了如何创建与春季父子关系多配置文件。 –