Spring integration 带注释的Spring集成简单桥

Spring integration 带注释的Spring集成简单桥,spring-integration,Spring Integration,我如何定义一个简单的网桥,它只使用java注释将一个directChannel连接到另一个directChannel 在xml中,可以这样做(取自) 但这给了我一个错误 IllegalArgumentException: '@BridgeFrom' is eligible only for 'MessageChannel' '@Bean' methods 关于如何将上述xml定义转换为java配置定义,有什么建议吗?我找到了使用@ServiceActivator的解决方法,但我不确定这是否10

我如何定义一个简单的网桥,它只使用java注释将一个directChannel连接到另一个directChannel

在xml中,可以这样做(取自)

但这给了我一个错误

IllegalArgumentException: '@BridgeFrom' is eligible only for 'MessageChannel' '@Bean' methods

关于如何将上述xml定义转换为java配置定义,有什么建议吗?

我找到了使用@ServiceActivator的解决方法,但我不确定这是否100%等效

@ServiceActivator(inputChannel = "inboundChannel", outputChannel = "outboundChannel")
public Message<?> bridge(Message<?> m) {
    return m;
}
@ServiceActivator(inputChannel=“inboundChannel”,outputChannel=“outboundChannel”)
公共消息桥(消息m){
返回m;
}
应该是

@Bean
@BridgeTo("output")
public MessageChannel input() {
    return new DirectChannel();
}

你的工作还可以,但效率有点低

编辑

如果您想要桥接两个通道,您无法控制的配置,或者您想要以不同的方式桥接“库”配置,这是一个更高效的版本

@Bean
@ServiceActivator(inputChannel="inboundChannel")
public MessageHandler bridge() {
    BridgeHandler handler = new BridgeHandler();
    handler.setOutputChannelName("outboundChannel");
    return handler;
}

请注意,输出通道位于处理程序上,而不是服务激活器注释上。有关此配置样式,请参阅。

谢谢您的回答。我只是不想注释输入/输出通道,因为我想根据spring配置文件激活它们之间的不同“桥接组件”。e、 一个简单的转发桥,一个变压器。。。使用xml定义的桥接器就可以实现这一点,我想我提供的是与xml片段完全等效的桥接器——从一个通道桥接到另一个通道。使用XML,我可以在公共配置中定义输入和输出通道,并在一个部分中定义桥接器。使用注释时,我需要直接注释输入/输出通道,因此无法控制它们与配置文件的连接方式。如果我使用sprign cloud stream Responsive,并且我想将通道桥接到@StreamMitter@output(Processor.output)上会怎么样?您的问题不清楚;请提出一个新问题,显示更多信息(而不是对一个已有一年历史的问题进行评论)。
@Bean
@BridgeTo("output")
public MessageChannel input() {
    return new DirectChannel();
}
@Bean
@BridgeFrom("input")
public MessageChannel output() {
    return new DirectChannel();
}
@Bean
@ServiceActivator(inputChannel="inboundChannel")
public MessageHandler bridge() {
    BridgeHandler handler = new BridgeHandler();
    handler.setOutputChannelName("outboundChannel");
    return handler;
}