无法发布TcpConnectionOpenEvent或TcpConnectionOpenEvent,分派器无法传递消息

问题描述

在春季集成中,我使用事件监听器来处理TcpConnectionopenEvent或TcpConnectionCloseEvent。

当我使用下面的代码博客时,我可以处理连接打开关闭应用程序事件,但我收到的警告日志如下

2020-08-11 11:15:46.857警告7104​​ --- [XNIO-1任务1] osiitcp.connection.TcpNetConnection:无法发布TcpConnectionopenEvent [SOME DETAIL] OPENED :调度程序无法传递消息;嵌套的异常是java.lang.NullPointerException

Traceback (most recent call last):
File "*****",line 
146,in <module>
 main()
File "*****",line 
127,in main
 mark_visited(data)
File "*****",line 
81,in mark_visited
 if data[mark_visited][3] == "v":
IndexError: list index out of range

这不会中断我的流程,但我想了解为什么我要使用此警告以及如何清除它。没有@EventListener的话,它就会消失...

感谢您的帮助

解决方法

如果您想访问应用程序上下文中的某些bean,则不能说new

我的意思是

directChannel.subscribe(new ServerConnectionStatusHandler());

因此,如果您创建类,则会创建一个非托管实例。同时,您需要自动连接现有的bean:

@Bean
public MessageChannel connectionStatusChannel(ServerConnectionStatusHandler handler) {
    DirectChannel directChannel = new DirectChannel();
    directChannel.subscribe(handler);
    return directChannel;
}
,

在listen(...)事件中对我来说似乎.getConnectionFactoryName()为null,或者connectionStatusHandler()可能返回null