国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

spring websocket的應用

2019-11-10 21:08:42
字體:
來源:轉載
供稿:網友

sPRing4之后的一個新特性就是整合了websocket

首先在pom.xml加入

<dependency>            <groupId>org.springframework</groupId>            <artifactId>spring-websocket</artifactId>            <version>4.2.8.RELEASE</version>        </dependency>

然后利用@Configuration配置websocket

@Configuration@EnableWebSocketpublic class WebSocketConfig implements WebSocketConfigurer {    @Override    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {        // TODO Auto-generated method stub        System.out.println("啟動websocket");        registry.addHandler(new TestHandler(), "/test").addInterceptors(new HandshakeInterceptor());    }}

其中“/test”就是url,后面可以增加一個攔截器。

public class TestHandler extends TextWebSocketHandler {    @Override    protected void handleTextMessage(WebSocketsession session, TextMessage message) throws Exception {      //具體的業務邏輯寫在這    }    @Override    public void afterConnectionEstablished(WebSocketSession session) throws Exception {        // TODO Auto-generated method stub        System.out.println("websocket啟動");    }    @Override    public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {        // TODO Auto-generated method stub        System.out.println(exception);    }    @Override    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {        // TODO Auto-generated method stub        System.out.println("連接關閉");    }}


上一篇:JVM-GC設計思路分析

下一篇:對象數組

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 蒙阴县| 平和县| 洞头县| 贵南县| 阿尔山市| 巴青县| 车致| 廊坊市| 揭西县| 政和县| 奎屯市| 泗水县| 荥经县| 台东县| 承德市| 大连市| 金门县| 灵丘县| 二手房| 日土县| 陆丰市| 缙云县| 开鲁县| 渝北区| 北票市| 江孜县| 闻喜县| 鄂托克前旗| 右玉县| 壶关县| 北宁市| 视频| 苗栗县| 台中县| 重庆市| 城口县| 华坪县| 扎赉特旗| 田东县| 布尔津县| 玉门市|