ServerEndpoint和web.xml
我有一些Soap,REST servlet和现在一个WebSocket:
@ServerEndpoint("/game") public class WebSocketgame{ ... }
我有下一个麻烦:如果web.xml存在,WebSocket不可见。 在web.xml中描述了jdbc资源,servlets ant等…当我删除web.xml时 – websocket成功可见。 我该如何解决这个问题?
更新web.xml:
com.sun.xml.ws.transport.http.servlet.WSServletContextListener ConfigServlet com.example.ConfigServlet 1 MainService com.sun.xml.ws.transport.http.servlet.WSServlet 1 ConfigServlet /ConfigServlet JsonServlet com.sun.jersey.spi.container.servlet.ServletContainer com.sun.jersey.config.property.packages com.example.json 1 JsonServlet /json/* propfile /WEB-INF/server_config.txt MainService /MainService 30 postgreSQL Datasource example jdbc/postgres javax.sql.DataSource Container
尝试添加
在beans.xml文件中
我相信你需要为那些像这样的人添加servlet配置
gameServer WebSocketgame.SocketEndPoint gameServer /game
我认为你应该配置你的主servlet(MainService)来提供所有urls /*
或/MainService/*
而不是使用websocket作为/MainService/game
。
你的class
@ServerEndpoint("/MainService/game") public class WebSocketgame{ ... }
和web.xml http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd“> com.sun.xml.ws.transport.http.servlet.WSServletContextListener ConfigServlet com.example.ConfigServlet 1 MainService com.sun.xml.ws.transport.http.servlet.WSServlet 1
ConfigServlet /ConfigServlet JsonServlet com.sun.jersey.spi.container.servlet.ServletContainer com.sun.jersey.config.property.packages com.example.json 1 JsonServlet /json/* propfile /WEB-INF/server_config.txt MainService /MainService/* 30 postgreSQL Datasource example jdbc/postgres javax.sql.DataSource Container
并使你的js(或其他websocket客户端)连接到/ MainService / game而不是/ game