2015-11-15 26 views
1

這是我之前發佈的一個關於將消息驅動通道適配器連接到多個隊列而不寫每個隊列的後續問題。動態入站適配器連接不起作用

How to hook up a list of message driven adapters without actually writing each one out?

我試圖按照建議的方法:

Spring multiple imapAdapter

現在我有這樣的一個配置(孩子),這需要性能從它的環境(如隊列名),並創建相應的消息驅動適配器。

@Autowired 
private ApplicationContext context; 

@Value("${id}") 
private String id; 

@Value("${primaryConnection}") 
private String primaryConnection; 

@Value("${queueName}") 
private String queueName; 

@Bean 
public IntegrationFlow primaryInitiationListenerFlow() { 
    return IntegrationFlows.from(Jms 
       .messageDriverChannelAdapter(context.getBean(primaryConnection, ConnectionFactory.class)) 
       .autoStartup(false) 
       .destination(queueName) 
       .configureListenerContainer(listenerContainerSpec()) 
       .id(id + "PrimaryIn") 
       .get()) 
      .channel("initiationChannel") 
      .get(); 
} 

在應用程序啓動我遍歷隊列名稱我有一個列表,併爲他們每個人的實例與我的主要方面如父上述背景下,並通過在適宜的環境。現在

public void onApplicationEvent(ContextRefreshedEvent event) { 
    for(String infoKey : clientConfig.getPairs().keySet()) { 
     PairInfo info = clientConfig.getPairs().get(infoKey); 
     Properties properties = info.getProperties(); 
     StandardEnvironment environment = new StandardEnvironment(); 
     environment.getPropertySources().addLast(new PropertiesPropertySource("connectionProps", properties)); 
     AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); 
     child.register(InboundFlow.class); 
     child.setId(properties.getProperty("id")); 
     child.setParent(context); 
     child.setEnvironment(environment); 
     child.refresh(); 
    } 
} 

所有的子上下文的這些實例被送入不同的隊列,並把這些消息到由父聽取在公共信道(的initiationChannel)。

@Bean 
public IntegrationFlow initiationAndDataFlow() { 
    return IntegrationFlows 
      .from("initiationChannel") 
      .handle(//doStuff) 
      .get(); 
} 

我父定義的initiationChannel和設置的東西,就像一個加里的例子一樣。

,但我發現這個錯誤說initiationChannel沒有出版時,我開始在Spring上下文:

Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: >Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: >Factory method 'initiationAndDataFlow' threw exception; nested exception is >java.lang.NoClassDefFoundError: org.reactivestreams.Publisher

我還挺需要加載(與用戶)父上下文第一,然後將其分配給每個孩子,所以當父母加載時,不會有任何人發佈到頻道。

我不知道我在做什麼錯。謝謝您的幫助。

回答

1

java.lang.NoClassDefFoundError: org.reactivestreams.Publisher

您錯過了類路徑中的reactive-streams-1.0.0.jar

您應該爲項目使用maven或gradle以確保解決所有依賴關係。

+0

哦,我完全誤解了錯誤信息對不起。我確實有maven。奇怪它沒有顯示在我的目標文件夾中。謝謝您的幫助。 – alokraop

相關問題