2013-10-14 72 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

嗨能否請您詳細闡述瞭如何創建與春季父子關係多配置文件。 –