gpt4 book ai didi

java - ServerEndpoint 和 web.xml

转载 作者:搜寻专家 更新时间:2023-10-30 23:03:05 29 4
gpt4 key购买 nike

我有一些 Soap、REST servlet,现在有一个 WebSocket:

@ServerEndpoint("/game")
public class WebSocketgame{
...
}

我有下一个麻烦:WebSocket 不可见,如果 web.xml 存在的话。在 web.xml 中描述了 jdbc 资源、servlets 和其他...当我删除 web.xml - websocket 成功可见。我该如何解决这个问题?

更新 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>ConfigServlet</servlet-name>
<servlet-class>com.example.ConfigServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>MainService</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>ConfigServlet</servlet-name>
<url-pattern>/ConfigServlet</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>JsonServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.example.json</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JsonServlet</servlet-name>
<url-pattern>/json/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>propfile</param-name>
<param-value>/WEB-INF/server_config.txt</param-value>
</context-param>
<servlet-mapping>
<servlet-name>MainService</servlet-name>
<url-pattern>/MainService</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

最佳答案

尝试添加

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="annotated">

在 beans.xml 文件中

关于java - ServerEndpoint 和 web.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26339217/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com