Java 动态入站适配器连接isn';行不通
嘿,这是我之前发布的一个问题的后续,这个问题是关于将消息驱动的通道适配器连接到多个队列,而不将每个队列都写出来 我试图遵循建议的方法: 现在我有了这个配置(子配置),它从它的环境中获取属性(比如队列名称),并相应地创建消息驱动适配器Java 动态入站适配器连接isn';行不通,java,spring,spring-integration,Java,Spring,Spring Integration,嘿,这是我之前发布的一个问题的后续,这个问题是关于将消息驱动的通道适配器连接到多个队列,而不将每个队列都写出来 我试图遵循建议的方法: 现在我有了这个配置(子配置),它从它的环境中获取属性(比如队列名称),并相应地创建消息驱动适配器 @Autowired private ApplicationContext context; @Value("${id}") private String id; @Value("${primaryConnection}") private String p
@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
,并像Gary在示例中所做的那样进行了设置
但是,当我启动spring上下文时,我收到这样一个错误,即initiationChannel
没有发布者:
通过工厂方法实例化Bean失败;
嵌套异常为org.springframework.beans.beans实例化异常:>未能实例化[org.springframework.integration.dsl.IntegrationFlow]:>工厂方法“initiationAndDataFlow”引发异常;嵌套异常为>java.lang.NoClassDefFoundError:org.reactivestreams.Publisher
我需要先加载父上下文(与订阅服务器一起),然后将其分配给每个子级,这样当有父上下文加载时,就不会有任何人发布到该频道
我不知道我做错了什么。谢谢你的帮助
java.lang.NoClassDefFoundError:org.reactivestreams.Publisher
您缺少类路径中的reactive-streams-1.0.0.jar
您应该在项目中使用maven或gradle,以确保所有依赖项都已解决。哦,我完全误解了错误消息,抱歉。我有maven。奇怪的是它没有显示在我的目标文件夹中。谢谢你的帮助。