我使用以下方法创建了一个Web应用程序 - HTML 5 - WebSocket(使用Tomcat 7) - 春天 - 休眠
问题出在我在Tomcat 7战争的部署期间:
org.apache.catalina.startup.ContextConfig parseWebXml
Grave: Erreur d'Úvaluation (parse) dans le fichier web.xml de l'application Ó jn
di:/localhost/mywebapp/WEB-INF/web.xml
org.xml.sax.SAXParseException; systemId: jndi:/localhost/mywebapp/WEB-INF/web.xm
l; lineNumber: 11; columnNumber: 12; Error at (11, 12) : org.apache.catalina.dep
loy.WebXml addServlet
这是我的web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My WebApp</display-name>
<servlet>
<servlet-name>Welcome</servlet-name>
<servlet-class>websocket.UrlWebSocketServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Welcome</servlet-name>
<url-pattern>/websocket/welcome</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
这是我的Servlet(WebSocket类):
public class UrlWebSocketServlet extends WebSocketServlet {
private static final Logger log = LoggerFactory.getLogger(UrlWebSocketServlet.class);
@Override
protected boolean verifyOrigin(String origin) {
log.trace("Origin: {}", origin);
return true;
}
@Override
protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) {
return new WebSocketConnection();
}
private static class WebSocketConnection extends MessageInbound {
@Override
protected void onOpen(WsOutbound outbound) {
log.info("Conexión abierta");
}
@Override
protected void onClose(int status) {
log.info("Conexión cerrada");
}
@Override
protected void onBinaryMessage(ByteBuffer byteBuffer) throws IOException {
log.warn("No se soportan mensajes binarios");
throw new UnsupportedOperationException("No se soportan mensajes binarios");
}
@Override
protected void onTextMessage(CharBuffer charBuffer) throws IOException {
final String user = charBuffer.toString();
log.debug("Mensaje recibido: {}", user);
getWsOutbound().writeTextMessage(CharBuffer.wrap("Hola " + user + " desde WebSocket"));
}
}
}
编辑:
这里是我的pom.xml的Tomcat jar部分:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.29</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
非常感谢:)
克里斯
答案 0 :(得分:3)
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.29</version>
</dependency>
应该说:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.29</version>
<scope>provided</scope>
</dependency>