Java Spring集成:TcpOutboundGateway获取目标解析异常:没有可用的输出通道或replyChannel标头
我正在尝试使用TcpOutboundGateway通过TCP与旧版(非spring)系统通信并处理响应,但出现以下错误:DestinationResolutionException:没有可用的输出通道或replyChannel标头 代码启动示例遗留侦听器,然后启动spring引导应用程序 我正在努力找出我做错了什么——或者我是否采取了正确的方法。如有任何建议,将不胜感激 (我在这里发布一些批注时遇到格式问题,因此删除@) 泰Java Spring集成:TcpOutboundGateway获取目标解析异常:没有可用的输出通道或replyChannel标头,java,spring-boot,spring-integration,Java,Spring Boot,Spring Integration,我正在尝试使用TcpOutboundGateway通过TCP与旧版(非spring)系统通信并处理响应,但出现以下错误:DestinationResolutionException:没有可用的输出通道或replyChannel标头 代码启动示例遗留侦听器,然后启动spring引导应用程序 我正在努力找出我做错了什么——或者我是否采取了正确的方法。如有任何建议,将不胜感激 (我在这里发布一些批注时遇到格式问题,因此删除@) 泰 请参阅中的注释。使用@ServiceActivator注释@Bea
请参阅中的注释。使用
@ServiceActivator
注释@Bean
时,输出通道需要在消息处理程序(网关Bean)上运行,而不是在注释上运行
您还应该不调用
start()
。让上下文来做。`@Bean@ServiceActivator(inputChannel=“sendChannel”)TcpOutboundGateway TcpOutboundGateway(){TcpOutboundGateway TcpOutboundGateway=new TcpOutboundGateway();TcpOutboundGateway.setConnectionFactory(tcpNetClientConnectionFactory());TcpOutboundGateway.setReplyChannel(replyChannel()));tcpOutboundGateway.setRequiresReply(true);返回tcpOutboundGateway;}`
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Test {
private static MessageChannel sendChannel;
@Bean
public MessageChannel replyChannel() {
return new DirectChannel();
}
@Bean
public MessageChannel sendChannel() {
MessageChannel directChannel = new DirectChannel();
sendChannel = directChannel;
return directChannel;
}
@Bean
TcpNetClientConnectionFactory tcpNetClientConnectionFactory() {
TcpNetClientConnectionFactory tcpNetClientConnectionFactory = new TcpNetClientConnectionFactory("me.me", 9003);
return tcpNetClientConnectionFactory;
}
@Bean
@ServiceActivator(inputChannel = "sendChannel", outputChannel = "replyChannel", requiresReply = "true")
TcpOutboundGateway tcpOutboundGateway() {
TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
tcpOutboundGateway.setConnectionFactory(tcpNetClientConnectionFactory());
tcpOutboundGateway.start();
return tcpOutboundGateway;
}
public static void main(String args[]) {
new LegacyApplication();
SpringApplication.run(Test.class, args);
Test.sendChannel.send(new GenericMessage("mgr?task=-1"));
}
}
@MessageEndpoint
class ReplyListener {
@ServiceActivator(inputChannel = "replyChannel")
public void telemetryHandler(String message) {
System.out.println(message);
}
}
class LegacyApplication implements Runnable {
public LegacyApplication() {
(new Thread(this)).start();
}
@Override
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(9003);
Socket clientSocket = serverSocket.accept();
System.out.println("LegacyApplication: Accepted");
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
System.out.println("LegacyApplication: " + in.readLine());
out.write("OK\r\n");
out.flush();
System.out.println("LegacyApplication: Done");
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}