按照git上的步骤在nutzwk里面集成了websocket插件;
集成方法如下:
1. 引入pom节点
org.nutz
nutz-plugins-websocket
1.r.60.r4
我的nutz主版本是 1.r.58 不会有问题吧??
2.实现自己的service类
@ServerEndpoint(value = "/websocket", configurator=NutWsConfigurator.class)
@IocBean
public class WebsocketService extends AbstractWsEndpoint {
}
3.在前段调用js初始化
websocket = new WebSocket("ws://localhost:8080/websocket");
websocket.onopen = function () {
setMessageInnerHTML("WebSocket连接成功");
}
目前遇到的问题:
web能够建立连接,同事输出日志"WebSocket连接成功";但是我在代码中
继承父类的方法
public void onOpen(Session session, EndpointConfig config) {
super.onOpen(session, config);
System.out.println("xxxxxxxxxxx 111111 ");
}
public void onClose(Session session, CloseReason closeReason) {
super.onClose(session, closeReason);
System.out.println("xxxxxxxxxxx 2222222 ");
}
....
里面所有的方法均未打印出日志,感觉是没进这些方法根本没有调用啊,不知道到底是启动还是没有启动,感觉是启动了,可是难道没有进入这些方法在后台启动的?
附日志:
[2017-04-11 03:44:46,587] Artifact CheKu:war exploded: Deploy took 12,061 milliseconds
2017-04-11 15:46:23,858 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'webSocketController'<class com.renxin.modules.controllers.open.message.WebSocketController>
2017-04-11 15:46:23,858 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=webSocketController
2017-04-11 15:46:23,858 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(webSocketController) in AnnotationIocLoader(packages=[cn.wizzer, com.renxin])
2017-04-11 15:46:23,859 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'webSocketController'<class com.renxin.modules.controllers.open.message.WebSocketController>
2017-04-11 15:46:23,860 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class com.renxin.modules.controllers.open.message.WebSocketController without AOP
2017-04-11 15:46:23,861 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'webSocketController' to [app]
xxxxxxxxxxxxuuuuu 0, 0, org.nutz.plugins.mvc.websocket.room.MemoryRoomProvider@1f556426
2017-04-11 15:46:53,168 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'webSocketController'<class com.renxin.modules.controllers.open.message.WebSocketController>
每次重新web端重新建立连接都会输出
2017-04-11 15:46:53,168 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'webSocketController'<class com.renxin.modules.controllers.open.message.WebSocketController>
bug没有看到我的 System.out.println("xxxxxxxxxxx 111111 "); 日志,好诡异。。。