急急急!!!Spring WebSocket集成到struts2项目里面去以后请求访问不了
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>
相关推荐
适合高校科研人员发布成果、寻找承接企业的靠谱技术转移平台有哪些?.docx
科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。
省级技术转移服务机构平台在支撑区域科技大脑建设方面能提供哪些数据服务?.docx
科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。
YOLO26算法城市道路交通标志目标检测+训练好的模型+8089张数据集+pyqt可视化界面-sts
文末有数据集可视化效果,供参考。YOLO26算法城市道路交通标志目标检测+训练好的模型+8089张数据集+pyqt可视化界面本资源由 sts 账号整理发布,标注齐全,开箱可训。
大模型和数据要素赋能采购行业数字化转型建设和实施方案.pptx
大模型和数据要素赋能采购行业数字化转型建设和实施方案.pptx
无刷直流电机BLDC转速电流双闭环+无位置传感器控制仿真【仿真+详解说明报告+参考文献】
无刷直流电机BLDC转速电流双闭环+无位置传感器控制仿真【仿真+详解说明报告+参考文献】内容概要:本文围绕三电平VIENNA整流器的双闭环控制与中点电位平衡问题展开研究,提出了一种基于上下电容电压差值补偿的中点电位平衡策略。该策略在传统电压外环与电流内环构成的双闭环PI控制基础上,引入电容电压差值作为反馈信号,结合SVPWM调制技术,利用冗余小矢量的时间分配调节中点电流,从而实现对中点电位的主动控制。仿真结果表明,所提方法在800 V直流母线电压下能有效抑制中点电位漂移,使上下电容电压高度均衡,且系统具备良好的动态响应能力和较低的输入电流THD,验证了控制方案的有效性与可行性。; 适合人群:从事电力电子与电力传动、新能源变换器、电能质量控制等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①掌握三电平VIENNA整流器的工作原理与中点电位波动成因;②学习双闭环PI控制的设计与参数整定方法;③理解基于SVPWM的中点电位平衡机制与实现路径;④为高效率、低谐波、高稳定性的AC-DC变换器设计提供理论依据与仿真参考。; 阅读建议:建议结合文中提供的MATLAB/Simulink仿真模型,深入理解控制框图与SVPWM模块的实现细节,重点关注差值补偿环与主控制环的耦合关系,并尝试在不同负载与动态工况下测试系统的鲁棒性,以加深对中点平衡边界与调节能力的认识。


