1、创建一个普通的Maven项目
2、导入依赖
必须要导入springboot的父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
</parent>
导入springboot的web启动器
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
因为导入了spring-boot-starter-parent的父项目,所以导入依赖的时候可以不用定义版本号,版本号会自动根据父项目的确定,可以进入spring-boot-starter-parent查看版本号
如果想要替换其他版本的jar包,例如mysql就在pom.xml文件中进行指定
<properties>
<mysql.version>5.1.43</mysql.version>
</properties>
查看版本树:pom文件中右击空白--->Diagrams--->Show Dependices
3、在java目录下编写主启动类
@SpringBootApplication//主程序类,这是一个springbooot的应用
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
4、编写Controller测试
package com.rk.boot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hanle01(){
return "Hello,Spring Boot";
}
}
5、测试-----启动主启动类,访问hello接口
6、springboot项目打jar包
1、在pom文件中添加插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.5.6</version>
</plugin>
</plugins>
</build>
2、启动Maven的package
3、测试-----cmd启动打包后的程序
cmd使用命令:java -jar springboot-01-helloworld-1.0-SNAPSHOT.jar
项目启动成功后访问:localhost:8088
7、简化部署
将项目打成jar包,直接在目标服务器执行jar包