添加 spring websockets 后,我无法访问(错误 404)我的 spring mvc web 应用程序
I can not access(error 404) to my spring mvc web app after adding spring websockets
将 Spring 网络套接字(工作正常)添加到我现有的 spring mvc 应用程序后,我无法访问该应用程序(所有应用程序网址均出现错误 404),但我可以访问插座很好。如果我恢复我添加到 spring-mvc.xml 文件的更改然后部署它们,应用程序可以正常工作。我不确定我做错了什么,你能帮帮我吗?
我刚刚在学习本教程 http://syntx.io/using-websockets-in-java-using-spring-4/ 我正在使用 spring 4.
这是我的Spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<context:component-scan base-package="com.mobile.automation.view.controller"/>
<context:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="websocket" class="com.mobile.automation.sockets.WebsocketEndPoint"/>
<websocket:handlers>
<websocket:mapping path="/testing" handler="websocket"/>
<websocket:handshake-interceptors>
<bean class="com.mobile.automation.sockets.HandshakeInterceptor"/>
</websocket:handshake-interceptors>
</websocket:handlers>
</beans>
WebsocketEndPoint.java
import org.springframework.stereotype.Controller;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
@Controller
public class WebsocketEndPoint extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session,
TextMessage message) throws Exception {
super.handleTextMessage(session, message);
TextMessage returnMessage = new TextMessage(message.getPayload()+" received at server");
session.sendMessage(returnMessage);
}
在此示例中,我没有看到与其他控制器或任何 MVC 配置相关的任何内容。
也许您的 spring-mvc.xml 文件中缺少这样的内容?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
</beans>
将 Spring 网络套接字(工作正常)添加到我现有的 spring mvc 应用程序后,我无法访问该应用程序(所有应用程序网址均出现错误 404),但我可以访问插座很好。如果我恢复我添加到 spring-mvc.xml 文件的更改然后部署它们,应用程序可以正常工作。我不确定我做错了什么,你能帮帮我吗?
我刚刚在学习本教程 http://syntx.io/using-websockets-in-java-using-spring-4/ 我正在使用 spring 4.
这是我的Spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<context:component-scan base-package="com.mobile.automation.view.controller"/>
<context:annotation-driven/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="websocket" class="com.mobile.automation.sockets.WebsocketEndPoint"/>
<websocket:handlers>
<websocket:mapping path="/testing" handler="websocket"/>
<websocket:handshake-interceptors>
<bean class="com.mobile.automation.sockets.HandshakeInterceptor"/>
</websocket:handshake-interceptors>
</websocket:handlers>
</beans>
WebsocketEndPoint.java
import org.springframework.stereotype.Controller;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
@Controller
public class WebsocketEndPoint extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session,
TextMessage message) throws Exception {
super.handleTextMessage(session, message);
TextMessage returnMessage = new TextMessage(message.getPayload()+" received at server");
session.sendMessage(returnMessage);
}
在此示例中,我没有看到与其他控制器或任何 MVC 配置相关的任何内容。
也许您的 spring-mvc.xml 文件中缺少这样的内容?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
</beans>