- 新建工程
- 使用Spring Initializr创建spring boot工程,按图设置工程属性
- 选择最新SpringBoot稳定版本2.6.1,并添加web支持
- 等待jar包的下载
- 对应的pom.xml
二、换源4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.1 com.example demo1 0.0.1-SNAPSHOT demo1 demo1 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
- 注意:start.spring.io这个网站可能访问不了
- 这里可以换用阿里镜像
- 需要注意的是使用阿里镜像,可能选择不了最新的SpringBoot版本
- 对应的pom.xml
4.0.0 com.example SprngBoot1 0.0.1-SNAPSHOT SprngBoot1 SprngBoot1 1.8 UTF-8 UTF-8 2.4.1 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-dependencies ${spring-boot.version} pom import org.apache.maven.plugins maven-compiler-plugin 3.8.1 1.8 1.8 UTF-8 org.springframework.boot spring-boot-maven-plugin 2.4.1 com.example.sprngboot1.SprngBoot1Application repackage repackage
如果需要用到最新版本的springboot,可以用2.6.1版本的pom将其替换掉
三、运行测试- 打开main函数,运行
- Tomcat运行成功
- 新建包Controller,添加HelloController
- HelloController源码
package com.example.demo1.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/")
public String hello(){
return "Hello World!";
}
}
- 打开浏览器,输入:http://localhost:8080/



