jdk1.8及以上 (配置好了之后可以在命令提示符中查看一下:java -version 以便后面打成jar包测试)
idea (我目前使用的是2018的)
2. 开始搭建1,打开idea 开始创建maven项目
2. 创建好之后是这样的(刚创建好的traget文件是没有的)
- 在pom.xml 文件中添加
4.0.0 com.ye springboot 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 2.4.0 org.springframework.boot spring-boot-starter-web org.projectlombok lombok true org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok
-
包的架构图如下:
-
在com.ye路径下创建一个启动类DemoApplication
package com.ye; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } -
在controller包下创建一个TestController
package com.ye.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("test") public class TestController { @GetMapping("/1") public String test(){ return "Hello World"; } } -
最好在resources 包下新建一个application.yml文件
server: port: 8081 # 不写的话,默认端口是8080 防止被其他应用占用
以上就是springboot的搭建了



