在pom.xml中引入依赖 springboot核心依赖
springboot引入spring-boot-starter-web,默认会引入tomcat
所以引入jetty先要排除掉tomcat,然后添加jetty的依赖,如下所示:
1 <!--配置父项目:维护版本-->
2 <parent>
3 <groupId>org.springframework.boot</groupId>
4 <artifactId>spring-boot-starter-parent</artifactId>
5 <version>2.5.2</version>
6 </parent>
7
8 <dependencies>
9 <!--springboot-starter-web依赖-->
10 <dependency>
11 <groupId>org.springframework.boot</groupId>
12 <artifactId>spring-boot-starter-web</artifactId>
13 <!--1.禁用tomcat-->
14 <exclusions>
15 <exclusion>
16 <groupId>org.springframework.boot</groupId>
17 <artifactId>spring-boot-starter-tomcat</artifactId>
18 </exclusion>
19 </exclusions>
20 </dependency>
21 <!--引入jetty依赖-->
22 <dependency>
23 <groupId>org.springframework.boot</groupId>
24 <artifactId>spring-boot-starter-jetty</artifactId>
25 </dependency>
26 </dependencies>
启动后如下:
控制层里:
1 package cn.jbit.controller; 2 3 import org.springframework.web.bind.annotation.RequestMapping; 4 import org.springframework.web.bind.annotation.RestController; 5 6 @RestController/*标注控制层所有的方法都是异步请求的方法(用来做测试)*/
7 public class UserController {
8 @RequestMapping("/hello")
9 public String hello(){
10 return "hello,Spring!!!!!";
11 }
12 }
启动类中:
1 package cn.jbit;
2
3 import org.springframework.boot.SpringApplication;
4 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
6 @SpringBootApplication/*标注启动类注解*/
7 public class SpringBoot02Application {
8 public static void main(String[] args) {
9 SpringApplication.run(SpringBoot02Application.class,args);
10 }
11 }
yml中 (看需求更改):
原文:https://www.cnblogs.com/Mr-Wang0428/p/15015663.html