Spring Websocket和404连接状态 [英] Spring Websocket and 404 status on connection

查看:532
本文介绍了Spring Websocket和404连接状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行于Tomcat 7.0.50下的Spring MVC 4.0.2正常工作项目中,我正在尝试按照

In a working Spring MVC 4.0.2 project running under Tomcat 7.0.50, I'm trying to implement Spring Websocket with simple broker and sockjs stomp endpoint, following the official reference. So, in the contextConfigLocation (DistpacherServlet property) I've add a value "websocket-config.xml" which contains:

>     <websocket:message-broker application-destination-prefix="/app" >
>           <websocket:stomp-endpoint path="/monitor">
>             <websocket:sockjs />
>           </websocket:stomp-endpoint>
>           <websocket:simple-broker prefix="/topic"/>
>     </websocket:message-broker>

当我启动Tomcat时,在eclipse控制台(catalina日志)中,显示行

In eclipse console (catalina log) when I start Tomcat, appear the rows

  • 初始化ExecutorService'clientInboundChannelExecutor'
  • 初始化ExecutorService'clientOutboundChannelExecutor'
  • 初始化ExecutorService'messageBrokerSockJsScheduler'
  • 将URL路径[/monitor/**]映射到类型为[class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]的处理程序上
  • Initializing ExecutorService 'clientInboundChannelExecutor'
  • Initializing ExecutorService 'clientOutboundChannelExecutor'
  • Initializing ExecutorService 'messageBrokerSockJsScheduler'
  • Mapped URL path [/monitor/**] onto handler of type [class org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler]

在jsp页面中,我输入了代码

In the jsp page I put the code

. . . .
var socket = new SockJS("monitor");
var stompClient = Stomp.over(socket); . . .

. . . .
var socket = new SockJS("monitor");
var stompClient = Stomp.over(socket); . . . .

不幸的是,当我从Chrome(v32)加载jsp页面时,出现此错误:

Unfortunately when I load the jsp page from Chrome (v32), I get this error:

无法加载资源:服务器的响应状态为404(未找到)

Failed to load resource: the server responded with a status of 404 (Not Found)

http://://localhost:8080/(ProjectName)/monitor/info

http ://localhost:8080/(ProjectName)/monitor/info

很显然,我正在本地进行此测试,然后可以从http://://localhost/(ProjectName)正确访问所有其他Webapp资源.

Obviously I'm doing this test locally, then all other webapp resources are reachable at http ://localhost/(ProjectName) correctly.

怎么了?

****更新2014年2月20日 我试图遵循已解决的堆栈问题,该问题建议将Tomcat8用于Spring Websocket,不幸的是它不起作用

**** Update 20 Feb 2014 I've tried to follow this resolved stack question, which suggests to use Tomcat8 for Spring Websocket, unfortunately it doesn't work

推荐答案

作为对/monitor/info的请求的结果,服务器端是否有任何日志输出? DispatcherServlet本身是如何映射的?我希望从上面的内容中获得"/".

Any log output on the server side as a result of the request to /monitor/info? How is the DispatcherServlet itself mapped? I would expect to "/" from what you have above.

SockJS端点基本上是在Spring MVC中映射的URL(带有SimpleUrlHandlerMapping),因此请尝试其他Spring MVC映射的控制器方法.并打开日志记录,是否可能有过滤器或其他返回404的信息?

The SockJS endpoint is basically a URL mapped in Spring MVC (with a SimpleUrlHandlerMapping) so try other Spring MVC mapped controller methods. And turn up logging, could there be a filter or something else returning the 404?

这篇关于Spring Websocket和404连接状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆