使用XML配置spring-websocket服务
发布时间:2020-12-16 22:36:46 所属栏目:百科 来源:网络整理
导读:在使用spring-websocket包搭建websocket服务一文中我们使用的是注解方式的来配置websocket。 下面我来将其改成xml方式的配置 一。更新Spring的xml命名空间,使其支持WebSocket ?xml version="1.0" encoding="UTF-8"?beans xmlns="http://www.springframework
在使用spring-websocket包搭建websocket服务一文中我们使用的是注解方式的来配置websocket。 下面我来将其改成xml方式的配置 一。更新Spring的xml命名空间,使其支持WebSocket <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:websocket="http://www.springframework.org/schema/websocket" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.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.xsd"> namespace其中添加了 xmlns:websocket="http://www.springframework.org/schema/websocket" http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket.xsd" 二。在context:component-scan 取消对WebSocketConfig的扫描
三。配置websocket:handlers <bean id="wsHandler" class="org.jstudioframework.websoket.handler.WebSocketHandler"/> <websocket:handlers> <websocket:mapping path="/websocket/socketServer.do" handler="wsHandler"/> <websocket:handshake-interceptors> <bean class="org.jstudioframework.websoket.interceptor.WebSocketHandshakeInterceptor"/> </websocket:handshake-interceptors> </websocket:handlers> 四,完整配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:websocket="http://www.springframework.org/schema/websocket" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.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.xsd"> <context:annotation-config/> <mvc:annotation-driven/> <context:component-scan base-package="org.jstudioframework.websoket.controller"/> <bean id="wsHandler" class="org.jstudioframework.websoket.handler.WebSocketHandler"/> <websocket:handlers> <websocket:mapping path="/websocket/socketServer.do" handler="wsHandler"/> <websocket:handshake-interceptors> <bean class="org.jstudioframework.websoket.interceptor.WebSocketHandshakeInterceptor"/> </websocket:handshake-interceptors> </websocket:handlers> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/"/> <property name="suffix" value=".jsp"/> </bean> </beans>五,运行测试,效果一样 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |