添加弹簧websockets后,我无法访问(错误404)我的spring mvc Web应用程序

时间:2015-01-30 20:10:52

标签: spring-mvc spring-security spring-websocket

将Spring网络套接字(工作正常)添加到我现有的spring mvc应用程序后,我无法访问该应用程序(所有应用程序URL的错误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);
    }

1 个答案:

答案 0 :(得分:1)

在此示例中,我没有看到与其他控制器或任何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>