我正在尝试使用websocket,所以按照这个例子[在这里] [1],我也试图用MVC架构实现这个,我的第一个调用将转到一个控制器然后该控制器将抛出适当的jsp页面,因此servlet-config.xml文件中有关于此类请求的映射(通常使用http请求调用jsp页面)。现在,当我试图从客户端进行握手时,它给出错误“ WebSocket连接到'ws:// localhost:8080 / WebSocketDemo / actions'失败:WebSocket握手期间出错:意外的响应代码:浏览器控制台上的“404 ”和“ org.springframework.web.servlet.DispatcherServlet noHandlerFound 警告:在tomcat控制台上找不到名为'mvc-dispatcher '“的DispatcherServlet中带有URI [/ WebSocketDemo / actions]的HTTP请求的映射。我想我错过了某种映射网址如“ws:// localhost ...”,那么究竟是什么问题以及可能的解决方案是什么。?
这是xml配置 -
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
<mvc:annotation-driven />
<mvc:resources location="/WEB-INF/resources/" mapping="/resources/**"/>
<context:component-scan base-package="com.syncoms.websocketController"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
WebSocketController有一个HomeController.java类,它只有一个方法.i。
@Controller
public class HomeController {
/**
* this method handles the request for the "index.html page"
* @return String (for which a page is declared in jsp folder)
*/
@RequestMapping("/index.html")
public String getHomePage()
{
return "index";
}
}