参考博客进行SSM+websocket整合

本文档详细介绍了如何在Spring MVC、Spring、MyBatis(SSM)框架下整合WebSocket技术。通过添加依赖,配置web.xml,以及客户端的URL设置,实现WebSocket通信。在过程中遇到了'No adapter for handler'的问题,解决办法是确保配置了能处理WebSocket的适配器,或者删除已有的不兼容适配器,利用默认的HttpRequestHandlerAdapter。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考博客地址:http://blog.youkuaiyun.com/gisredevelopment/article/details/38392629#

参考博客名称:spring+websocket整合(springMVC+spring+MyBatis即SSM框架和websocket技术的整合)

搭建环境:tomcat 7, jdk 8


搭建步骤:

一、在maven的pom.xml中加入websocket所依赖的jar包,spring版本4.0(同原文)

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.3.0</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-websocket</artifactId>
   <version>4.0.1.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-messaging</artifactId>
   <version>4.0.1.RELEASE</version>
</dependency>

二、【原文】 更新web.xml中namespace.xsd的版本。 这里不是web.xml文件,而是配置websocket handler的文件里,如applicationContext.xml或者spring-XXX.xml文件(我这里即spring-mvc.xml文件),否则配置handler的文件会报错。

<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:websocket="http://www.springframework.org/schema/websocket"
	   xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket.xsd">
三、 创建websocket处理类(同原文)

public class WebsocketEndPoint extends TextWebSocketHandler {
	@Override
	protected void handleTextMessage(WebSocketSession session,TextMessage message) throws Exception {
		super.ha
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值