急急急!!!Spring WebSocket集成到struts2项目里面去以后请求访问不了

zzz小菜鸟zzz 2016-01-20 02:52:53
正常的demo里面可以访问到的
1、配置已经扫描到 项目启动服务可以注册

@Configuration
@EnableWebSocket
@EnableWebMvc
public class WebSocketConfig extends WebMvcConfigurerAdapter implements WebSocketConfigurer{

@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
//注册两种:ws 和http 实现websocke
System.out.println("注册websocket服务开始------------");
registry.addHandler(systemWebSocketHandler(), "/webSocketServer").addInterceptors(new MyHandshakeInterceptor());
registry.addHandler(systemWebSocketHandler(), "/sockjs/webSocketServer").addInterceptors(new MyHandshakeInterceptor()).withSockJS();
System.out.println("注册websocket服务完成------------");

}

@Bean
public WebSocketHandler systemWebSocketHandler(){
return new SystemWebSocketHandler();
}
}


2. 浏览器支持websocket,用ws = new WebSocket('ws://localhost:7080/webSocketServer');访问时访问不了
报错:

WebSocket connection to 'ws://localhost:7080/webSocketServer' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED


3.application.xml头:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:websocket="http://www.springframework.org/schema/websocket"
xsi:schemaLocation="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/websocket
http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd"
default-autowire="byName" default-lazy-init="false">

4.struts.xml添加了:
<constant name="struts.action.excludePattern" value=".*validcode.*,.*webSocketServer*,/webSocketServer,^ws://.$,ws://.*,/webSocketServer.*"/>

5 过滤器里面对url放行了:
if(!uri.equals("/websocket/p2pchat")&& !uri.equals("/webSocketServer")&&!uri.equals("/websocket/p2pchat1")){
//省略
}else{
chain.doFilter(httpRequest, httpResponse);
}
6、web.xml里面struts2配置:
<filter id="filterdispatcher">
<filter-name>Struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
...全文
341 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
s09122289 2016-06-15
  • 打赏
  • 举报
回复
卤煮解决了没啊 分享下呗
zhaojinmeng 2016-04-01
  • 打赏
  • 举报
回复
楼主解决了吗?遇到同样问题
tianfang 2016-01-31
  • 打赏
  • 举报
回复
部署环境也说一下
gggggame 2016-01-31
  • 打赏
  • 举报
回复
遇到同样的问题,最后楼主解决了吗
jizhuiyi671 2016-01-20
  • 打赏
  • 举报
回复
表示看不懂
zzz小菜鸟zzz 2016-01-20
  • 打赏
  • 举报
回复
急急急 求大神指导一下

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧