2017-07-17 66 views
0

我使用tomcat 7.0.77,spring,現在sockjs無法打開信息。 的web.xmlsockjs信息404錯誤

 <servlet> 
       <servlet-name>mvc-dispatcher</servlet-name> 
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
       <load-on-startup>1</load-on-startup> 
       <async-supported>true</async-supported> 
     </servlet> 

     <servlet-mapping> 
       <servlet-name>mvc-dispatcher</servlet-name> 
       <url-pattern>/cmd/*</url-pattern> 
       <url-pattern>/webSocketServer</url-pattern> 
       <url-pattern>/sockjs/webSocketServer/*</url-pattern> 
       <url-pattern>/sockjs/webSocketServer/info</url-pattern> 
       <url-pattern>/webSocketServerLogout</url-pattern> 
       <url-pattern>/webSocketServerSpAlarm</url-pattern> 

的java

public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer { 
    @Override 
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 
//  registry.addHandler(systemWebSocketHandler(),"/webSocketServer").addInterceptors(new WebSocketHandshakeInterceptor()); 

     registry.addHandler(systemWebSocketHandler(), "/sockjsWebSocketServer").addInterceptors(new WebSocketHandshakeInterceptor()) 
.withSockJS(); 

catalina.out中 INFO:映射的URL路徑[/ sockjs/webSocketServer/**]到類型的處理程序[類org.springframework.web.socket .sockjs.support.SockJsHttpRequestHandler] 2017年7月17日下午1點01分46秒org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler

HTML

websocket = new SockJS("http://"+local+"/sockjs/webSocketServer"); 

首先不能打開/ sockjs/webSocketServer /信息當我添加/ sockjs/webSocketServer /信息到像上面的web.xml, http://172.24.170.178/sockjs/webSocketServer/093/vl3vnd0p/websocket 404錯誤

感謝報告

+0

catalina.out報告2017年7月17日上午5點14分28秒org.springframework.web.servlet.PageNotFound noHandlerFound 警告:在名爲'mvc'的DispatcherServlet中未找到具有URI [/ sockjsWebSocketServer/info]的HTTP請求的映射-dispatcher」 – johnie

回答

0

附加Servlet映射/ sockjs/*到web.xml 並將html更改爲 websocket = new SockJS(「http://」+ local +「/ sockjs/sockjsWebSocketServer」);

現在好了。 因爲對於sockjs,在webConfig中java映射url不能直接把它放到web.xml中。 需要添加一個前綴sockjs(示例)。