依赖总括
-
核心依赖:Spring Web、Spring Data JPA、MySQL Driver。
-
开发工具:Lombok、Spring Boot DevTools。
-
安全与权限:Spring Security。
-
测试与文档:Spring Boot Starter Test、Swagger。
-
性能优化:Spring Boot Starter Cache、Redis。
-
监控与管理:Spring Boot Starter Actuator。
spring-boot-starter-parent
springboot项目的总(父)依赖,主要负责版本管理
XML
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

当我们使用 spring 或 spring-boot 开发项目时,需要引入很多依赖,包括 spring 本身的组件、各种 spring-boot-starter、以及其它第三方依赖(如:slf4j、redis)。依赖多了,版本的选择是个问题,就怕哪个版本选择的不对导致出现一些意想不到的 BUG。
spring-boot-dependencies的作用主要是起到约束版本的作用,在这个包里面声明了各种版本号。如果当下面的< dependency >中用到就可以不用配置版本号< version >
spring-boot-starter-web
可执行的 Web 应用且内含SpringBoot核心启动器,包含各种springboot的配置日志等,创建项目时会自动引入该依赖
XML
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
spring-boot-starter-web 中包含了 spring-boot-starter等,所以就不需要再配置 spring-boot-starter 依赖

spring-boot-starter支持注解:@controller、@Service、@Component、@Resource 是spring的,所以spring boot创建完成后就可以使用
spring-boot-starter-web支持注解:@RestController、@RequestMapping、@ResponseBody、@JsonFormat
mybatis-plus-boot-starter
spring-boot-starter-jdbc
主要提供了三个功能:第一个是对数据源的装配,第二个是提供一个JdbcTemplate简化使用,第三个是事务。
druid-spring-boot-3-starter
mysql-connector-java
mysql连接依赖。
springboot会根据我们引入的数据库连接依赖,自动配置数据库的驱动,因此我们可以不需要配置数据库的驱动项。所以一般情况下我们只需要 spring-boot-starter-jdbc, mysql-connector-java 两个依赖,如果需要mybatis,则再加上mybatis依赖
lombok
@Data 注解,自动生成Getter、Setter、构造函数等代码
@Slf4j 注解,不需要单独引入日志依赖和配置日志,直接 log.info( ) 打印日志
XML
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
</dependency>
spring-boot-starter-aop
面向切面编程AOP
@AspectJ、@Pointcut,@Before、@After等,@Aspect和自定义注解
spring-boot-starter-test
用于编写springboot Test测试类
XML
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
spring-boot-devtools
springboot热部署,修改java代码后,不用重启项目就能直接最新测试,省略了不断修改代码不断重启项目的麻烦
XML
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>