Spring boot创建时常用的依赖

新建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
### Spring Boot 常用 Starter 依赖列表及作用 以下是 Spring Boot常用的一些 Starter 依赖及其具体的作用: #### spring-boot-starter-web 此依赖用于构建基于 Spring MVC 的 Web 应用程序,提供嵌入式的 Tomcat 容器以及必要的依赖来支持 RESTful 和其他类型的 Web 开发[^1]。 #### spring-boot-starter-data-jpa 该依赖提供了与 JPA(Java Persistence API)集成的支持,允许开发者轻松实现数据库访问层的功能。它还包含了 Hibernate 等 ORM 工具的相关依赖[^2]。 #### spring-boot-starter-test 这是一个测试工具的集合,包含JUnit、Mockito和其他有用的库,能够方便地对应用程序进行单元测试和集成测试[^3]。 #### spring-boot-starter-security 这个 Starter 提供了安全机制的基础设置,包括认证和授权等功能,利用 Spring Security 来保护应用免受未经授权的访问[^4]。 #### spring-boot-starter-thymeleaf 如果项目需要模板引擎渲染 HTML 页面,则可以选择 Thymeleaf 作为视图技术,而此依赖正好封装好了所需的一切配置和支持。 #### spring-boot-starter-mail 当业务逻辑涉及发送电子邮件,可以借助此模块完成邮件服务的搭建工作,内部集成了 JavaMail Sender 接口及相关组件。 #### spring-boot-starter-cache 为了提高性能并减少重复计算资源消耗的情况发生,在某些场景下可能需要用到缓存管理方案;此就可以引入本 Starter 实现本地或者分布式环境下的数据存储优化策略。 #### spring-boot-starter-aop 面向切面编程(AOP)是一种非常重要的设计模式之一,特别是在处理横切关注点方面表现尤为突出——比如日志记录、事务控制等等操作都可以通过 AOP 技术优雅解决。因此,如果有这方面需求的话,那么就应该考虑加入此项依赖到工程当中去。 #### spring-boot-starter-hateoas 这一项主要服务于创建遵循 HATEOAS (Hypermedia As The Engine Of Application State)原则的超媒体驱动型 REST APIs ,从而使得客户端可以根据返回的结果动态调整请求行为而不必事先知道服务器端的具体结构信息。 ```java <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-hateoas</artifactId> </dependency> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值