新建SpringBoot Maven项目中pom常用依赖配置及常用的依赖的介绍
1.springboot项目的总(父)依赖大全
<parent>
<artifactId>spring-boot-dependencies</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.3.3.RELEASE</version>
</parent>
当我们使用 spring 或 spring-boot 开发项目时,需要引入很多依赖,包括 spring 本身的组件、各种 spring-boot-starter、以及其它第三方依赖(如:slf4j、redis)。依赖多了,版本的选择是个问题,就怕哪个版本选择的不对导致出现一些意想不到的 BUG。
spring-boot-dependencies的作用主要是起到约束版本的作用,在这个包里面声明了各种版本号,供子项目去引用。类似spring-cloud-dependencies和spring-cloud-alibaba-dependencies则是去声明cloud和cloud-alibaba组件的版本。具体有些什么可以点进去看看就知道了。如果当下面的< dependency >中用到就可以不用配置版本号< version >
2.可执行的 Web 应用且内含SpringBoot核心启动器,包含各种springboot的配置日志等,创建项目时会自动引入该依赖
支持注解:@controller、@Service、@Component、@Resource 是spring的,所以spring boot创建完成后就可以使用(由spring-boot-starter支持)
支持注解:@RestController、@RequestMapping、@ResponseBody、@JsonFormat(由spring-boot-starter-web支持)
<!--Spring Boot Web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
spring-boot-starter-web 是什么?
spring-boot-starter-web是一个依赖库,Spring Boot 是在 Spring 的基础上创建的一个开原框架,它提供了 spring-boot-starter-web (web场景启动器)来为web开发予以支持。spring-boot-starter-web 提供了嵌入的Servlet容器以及SpringMVC提供了大量自动配置,可以适用于大多数web开发场景。
只要我们在Spring Boot 项目中的 pom.xml 中引入了spring-boot-starter-web依赖,即使不进行任何配置,也可以使用Spring MVC 进行 Web 开发。Spring Web的启动程序使用Spring MVC, REST和Tomcat作为默认的嵌入式服务器。单个spring-boot-starter-web依赖关系可传递地获取与Web开发相关的所有依赖关系。它还减少了构建依赖项计数。
配置了该依赖就不用再配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
因为spring-boot-starter-web包含了spring-boot-starter等,可以点进去看看
3.junit测试,创建项目时会自动引入该依赖
用于编写springboot Test测试类
SpringBoot Test测试类的使用
<dependency>
<groupId>org.spring