建立spring boot整合webSocket前後端訊息傳送的實現
阿新 • • 發佈:2020-08-10
整體功能說明
前後臺可以對多個webSocket進行資料變更的傳播。支援心跳
1.建立專案
2.新建web目錄
新建web目錄存放前端靜態檔案
3.注入依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.3.1.RELEASE</version> </dependency> <!--websocket連線需要使用到的包--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> <version>2.3.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>2.3.1.RELEASE</version> <scope>test</scope> </dependency>
靜態檔案打包(紅字)
<build> <resources> <resource> <directory>src/main/web</directory> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> </resources><plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>