springboot+websocket使用报错一


APPLICATION FAILED TO START


Description:

Parameter 0 of constructor in com.socket.socketIo.MessageEventHandler required a bean of type ‘com.corundumstudio.socketio.SocketIOServer’ that could not be found.
按照正常的依赖添加,程序引入后报上面错误,查看MessageEventHandler 中的代码:

@Component
public class MessageEventHandler {
    //    @Autowired
    public static SocketIOServer socketIoServer;
    //    static ArrayList<UUID> listClient = new ArrayList<>();
    private static Vector<UUID> vectorClient = new Vector<>();//客户端缓存,线程安全
    //改为address集合
//    private static Vector<String> strings = new Vector<>();//客户端缓存,线程安全
    //    static final int limitSeconds = 60;

    @Autowired
    public MessageEventHandler(SocketIOServer socketIOServer) {
        this.socketIoServer = socketIOServer;
    }

    @OnConnect
    public void onConnect(SocketIOClient client) {
        //        #########################
        //        判空
        if (vectorClient == null || vectorClient.size() == 0) {
            System.out.println("添加了" + client.getRemoteAddress());
            vectorClient.add(client.getSessionId());
        } else {
            for (UUID uuid : vectorClient) {
                if (new String(socketIoServer.getClient(uuid).getSessionId() + "").equals(new String(client.getSessionId() + ""))) {
                    System.out.println("相等:不添加");
                    System.out.println(new String("----" + socketIoServer.getClient(uuid).getSessionId()));
                    System.out.println(new String(client.getSessionId() + "---"));
                    break;
                } else {
                    System.out.println("不等:添加了" + client.getRemoteAddress());
                    vectorClient.add(client.getSessionId());
                }
            }
        }
        //        ##########################
        //        vectorClient.add(client.getSessionId());
        //      listClient.add(client.getSessionId());
        //        System.out.println("客户端:" + client.getRemoteAddress() + "已连接");
    }}

发现是@Component引发的问题,注释掉后,程序正常执行。


版权声明:本文为whwwycl原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。