我有这个简单的websocket
@ServerEndpoint(
value="/data",
encoders = {WsCommandEncoder.class},
decoders = {WsCommandDecoder.class}
)
public class DataWebSocket {
//...impl
}
我在主要功能中初始化我的嵌入式tomcat
public static void main(String[] args) throws Exception{
Tomcat tomcat = new Tomcat();
tomcat.setPort(6000);
//how do i add the websocket to my tomcat instance?
String webDir = "/web";
tomcat.addWebapp("/", new File(webDir).getAbsolutePath());
System.out.println("configuring app with basedir: " + new File("./" + webDir).getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
}
我以前从未使用过嵌入式tomcat,通常有web.xml,但我不想使用webxml,我想直接在代码中添加端点,那么如何将websocket添加到我的tomcat实例?
我正在使用Tomcat 8.0.9和Java EE 7
看一下Tomcat单元测试的源代码,尤其是WebSocket的源代码。有许多通过代码添加端点的示例。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句