目录
一、项目依赖
<!-- web启动包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- 去除内置tomcat -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- jetty容器替代Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
因为jetty从版本7以后自己内置实现了websocket,所以在依赖文件中就不需要引入其他webscoket依赖包
二、实现方式
1、方式一:使用注解
springBoot启动类
@SpringBootApplication
@ServletComponentScan // 必需---> 这个注解为了扫描自定义servlet
public class JettyWeSocketApplication {
public static void main(String[] args) {
SpringApplication.run(JettyWeSocketApplication .class, args);
}
}
配置webscoket

本文介绍了如何使用Spring Boot和Jetty在项目中实现WebSocket功能,包括依赖管理、两种实现方式(注解和容器管理)、处理连接与信息的方法,以及通过WebSocket在线测试工具进行的项目启动测试。
最低0.47元/天 解锁文章
2350

被折叠的 条评论
为什么被折叠?



