1.创建一个maven项目
2.在pom.xml配置文件中添加依赖(添加后要刷新一下)
org.springframework.boot spring-boot-starter-parent 2.5.4 org.springframework.boot spring-boot-starter-web
3.编写Application类和实体类可以将控制启动器和请求控制器写在一个类里面
@RestController
@EnableAutoConfiguration
public class MyApplication {
@RequestMapping("/")
public String hello(){
return "hello,leniy";
}
public static void main(String[] args) {
SpringApplication.run(MyApplication.class,args);
}
}
4.启动这个类,springboot内置了tomcat容器,不需要把项目部署到tomcat上就可以使用,在浏览器访问localhost:8080即可
补充1.在resouces文件夹下可以创建一个springboot.properties文件来对配置进行修改,比如servers.port=8888可以修改端口号。
2.对maven的setting.xml进行了修改,声明java版本,添加了阿里云的镜像。
3.在pom.xml添加配置,可以让springboot打包生成可执行的jar文件包
org.springframework.boot spring-boot-maven-plugin
之后可以在项目的target文件夹中找到jar包,使用命令行运行。



