Spring boot创建时常用的依赖
新建SpringBoot Maven项目中pom常用依赖配置及常用的依赖的介绍1.springboot项目的总(父)依赖大全parent artifactIdspring-boot-dependencies/artifactId groupIdorg.springframework.boot/groupId version2.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 groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId /dependencyspring-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 groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter/artifactId /dependency因为spring-boot-starter-web包含了spring-boot-starter等可以点进去看看3.junit测试创建项目时会自动引入该依赖用于编写springboot Test测试类SpringBoot Test测试类的使用dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-test/artifactId scopetest/scope /dependency4.mysql数据配置配置mysql依赖时不写版本号xx.xx.xx的话就会引入mysql依赖的默认版本SpringBoot2.1.x以后默认使用的是mysql 8版本SpringBoot2.1.x之前默认使用的是mysql 5.x版本在配置数据源的时候就有差异了:配置低版本 5.xx.xxspring.datasource.driver-class-namecom.mysql.jdbc.Driver spring.datasource.urljdbc:mysql://localhost:3306/student?useUnicodetruecharacterEncodingUTF-8useSSLfalse spring.datasource.usernameroot spring.datasource.password123456配置高版本 8.xx.xxspring.datasource.driver-class-namecom.mysql.cj.jdbc.Driver spring.datasource.urljdbc:mysql://localhost:3306/student?serverTimezoneGMT%2B8useUnicodetruecharacterEncodingUTF-8useSSLfalse spring.datasource.usernameroot spring.datasource.password123456 !--MySQL 连接组件-- dependency groupIdmysql/groupId artifactIdmysql-connector-java/artifactId scoperuntime/scope /dependency5.mybatis数据处理层持久层框架连接数据库着重点放在了编写sql上而不是通过jdbc传统方式来不断操作Connection、Statment、ResultSet注解Mapper 指定映射接口application.yaml配置文件中配置自动识别的xmlmybatis:mapper-locations: classpath:mapper/**/*.xmltype-aliases-package: run.leave.mapper!--MyBaits-- dependency groupIdorg.mybatis.spring.boot/groupId artifactIdmybatis-spring-boot-starter/artifactId version2.1.2/version /dependency8.Druid连接池druid和druid-spring-boot-starter 的区别与报错Cannot resolve configuration property ‘spring.datasource.xxx解决!--Druid-- !--可以不配这个因为druid-spring-boot-starter里面已经有了随便带着一下这个依赖代码可读性高一点反正对其他啥也没影响-- dependency groupIdcom.alibaba/groupId artifactIddruid/artifactId version1.2.8/version /dependency !-- Druid Spring Boot 组件-- dependency groupIdcom.alibaba/groupId artifactIddruid-spring-boot-starter/artifactId version1.2.8/version /dependency在yaml文件中配置使用spring: datasource: # 数据源基本配置 url: jdbc:mysql://localhost:3306/hotel?useUnicodetruecharacterEncodingutf-8serverTimezoneAsia/Shanghai username: root password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource # 数据源其他配置 druid: # 配置初始化大小、最小、最大线程数 initialSize: 5 minIdle: 5 # CPU核数1也可以大些但不要超过20数据库加锁时连接过多性能下降 maxActive: 20 # 最大等待时间内网800外网1200三次握手1s maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最大空间时间单位是毫秒 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 testWhileIdle: true # 设置从连接池获取连接时是否检查连接有效性true检查false不检查 testOnBorrow: true # 设置从连接池归还连接时是否检查连接有效性true检查false不检查 testOnReturn: true # 可以支持PSCache提升写入、查询效率 poolPreparedStatements: true # 配置监控统计拦截的filters去掉后监控界面sql无法统计wall用于防火墙 filters: stat,wall,log4j # 保持长连接 keepAlive: true maxPoolPreparedStatementPerConnectionSize: 20 useGlobalDataSourceStat: true connectionProperties: druid.stat.mergeSqltrue;druid.stat.slowSqlMillis5007.Json格式转换工具FastjsonFastjson 是一个 Java 库可以将 Java 对象转换为 JSON 格式当然它也可以将 JSON 字符串转换为 Java 对象。Java中 Json、String、jsonObject、jsonArray格式之间互相转换dependency groupIdcom.alibaba/groupId artifactIdfastjson/artifactId version1.2.78/version /dependency8.lombooklombok最优秀的就是注解了一个注解就干掉了很多代码实体类中的注解.Data 直接可以省略了Get、Set方法Slf4j 不需要单独引入日志依赖和配置日志直接 log.info( ) 打印日志如何在IDE编译器 中使用lombok插件idea中可以直接在编译器中搜索下载就不多阐述了eclipse则需要从官网下载lombok.jar包然后双击启动jar包逐步操作指向eclisp.exe重启eclipse即可!--LomBok-- dependency groupIdorg.projectlombok/groupId artifactIdlombok/artifactId /dependency9.面向切面编程AOP支持的注解AspectJ、Pointcut、通知注解如Before、After等、Aspect和自定义注解spring-boot-starter-aop及其使用场景说明SpringBoot 中的 Aop 注解使用 自定义注解!--Spring Boot Aop-- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-aop/artifactId /dependency10.Validation校验参数的实现支持的注解MaxMin等常用注解和demo!--Spring Validation-- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-validation/artifactId /dependency11.Actuator 监控主要是服务器运维使用开发过程不常用springboot 监控 Actuator 的设置!--Spring Boot Actuator-- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-actuator/artifactId /dependency12.hutool工具包提供了很多封装方法供开发者使用!--Hutool-- dependency groupIdcn.hutool/groupId artifactIdhutool-all/artifactId version5.4.7/version /dependency13.jupiter其依赖包含了junit-jupiter-api、junit-jupiter-engine、junit-vintage-engineJunit-jupiter-api 和 junit-jupiter-engine 的区别总结Junit4,Junit5,Jupiter之间的联系值得一看!--Junit-- dependency groupIdorg.junit.jupiter/groupId artifactIdjunit-jupiter/artifactId scopetest/scope /dependency14.打包配置用于生成部署到服务器的包JAVA项目在服务器部署过程build plugins plugin groupIdorg.springframework.boot/groupId artifactIdspring-boot-maven-plugin/artifactId executions execution goals goalrepackage/goal /goals /execution /executions /plugin /plugins /build15.多yaml文件配置指定其使用那个文件,不配置下面的profiles但创建的文件格式形如这样也是可用的在这里插入图片描述在这里插入图片描述在这里插入图片描述profiles profile iddev/id activation activeByDefaulttrue/activeByDefault /activation properties profilesActivedev/profilesActive /properties /profile profile idpro/id properties profilesActivepro/profilesActive /properties /profile /profiles16.使用properties标签统一编码和JAVA版本!--统一编码和JAVA版本-- properties project.build.sourceEncodingUTF-8/project.build.sourceEncoding maven.compiler.source1.8/maven.compiler.source maven.compiler.target1.8/maven.compiler.target java.version1.8/java.version /properties17.mybatis-plus在mybatis基础上的升级版工具避免了使用mybatis时需要编写大量的xml文件dependency groupIdcom.baomidou/groupId artifactIdmybatis-plus-boot-starter/artifactId version3.4.2/version /dependency18.springboot热部署修改java代码后不用重启项目就能直接最新测试省略了不断修改代码不断重启项目的麻烦dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-devtools/artifactId optionaltrue/optional /dependency

相关新闻

Spring boot启动原理及相关组件

Spring boot启动原理及相关组件

优质博文:IT-BLOG-CN 一、Spring Boot应用启动 一个Spring Boot应用的启动通常如下: SpringBootApplication Slf4j public class ApplicationMain {public static void main(String[] args) {ConfigurableApplicationContext ctx SpringApplication.…

2026/5/17 9:32:16 阅读更多 →
Flutter 三方库 pubspec_yaml 的鸿蒙化适配指南 - 掌控配置元数据资产、YAML 治理实战、鸿蒙级精密定义专家

Flutter 三方库 pubspec_yaml 的鸿蒙化适配指南 - 掌控配置元数据资产、YAML 治理实战、鸿蒙级精密定义专家

欢迎加入开源鸿蒙跨平台社区:https://openharmonycrossplatform.csdn.net Flutter 三方库 pubspec_yaml 的鸿蒙化适配指南 - 掌控配置元数据资产、YAML 治理实战、鸿蒙级精密定义专家 在鸿蒙跨平台应用执行高级配置管理与多维 YAML 资产指控(如构建一个…

2026/7/3 6:49:25 阅读更多 →
自动生成接口:XinServer 是如何让接口开发变得不需要代码的

自动生成接口:XinServer 是如何让接口开发变得不需要代码的

自动生成接口:XinServer 是如何让接口开发变得不需要代码的 兄弟们,不知道你们有没有过这种经历:产品经理或者甲方爸爸又提新需求了,要加个用户积分系统,或者搞个活动报名功能。你作为前端或者移动端开发,心…

2026/5/17 9:32:16 阅读更多 →

最新新闻

CMS备份与恢复:Instatic完整灾难恢复演练

CMS备份与恢复:Instatic完整灾难恢复演练

CMS备份与恢复:Instatic完整灾难恢复演练 【免费下载链接】Instatic Instatic is a modern self-hosted visual CMS - get it running in 1 minute 项目地址: https://gitcode.com/GitHub_Trending/in/Instatic Instatic作为一款现代化自托管视觉CMS&#xf…

2026/7/4 7:21:01 阅读更多 →
status-go终极指南:构建去中心化社交应用的完整Go后端解决方案

status-go终极指南:构建去中心化社交应用的完整Go后端解决方案

status-go终极指南:构建去中心化社交应用的完整Go后端解决方案 【免费下载链接】status-go The "backend" library for Status Apps 项目地址: https://gitcode.com/gh_mirrors/st/status-go 想要快速构建去中心化社交应用?&#x1f68…

2026/7/4 7:16:59 阅读更多 →
为什么选择Slash?对比原生NSAttributedString,这款富文本工具到底强在哪里?

为什么选择Slash?对比原生NSAttributedString,这款富文本工具到底强在哪里?

为什么选择Slash?对比原生NSAttributedString,这款富文本工具到底强在哪里? 【免费下载链接】Slash A better way to create attributed strings 项目地址: https://gitcode.com/gh_mirrors/slash/Slash 如果你是iOS或macOS开发者&…

2026/7/4 7:16:59 阅读更多 →
如何将Statsig Status Page部署到自定义域名:完整教程

如何将Statsig Status Page部署到自定义域名:完整教程

如何将Statsig Status Page部署到自定义域名:完整教程 【免费下载链接】statuspage A simple, zero-dependency, pure js/html status page based on GitHub Pages and Actions. 项目地址: https://gitcode.com/gh_mirrors/sta/statuspage Statsig Status Pa…

2026/7/4 7:14:59 阅读更多 →
CANN/PID批量滚动评分算法

CANN/PID批量滚动评分算法

PidFopdtBatchRolloutScore Algorithm 【免费下载链接】mat-chem-sim-pred 面向工业领域,聚焦计算仿真、预测两大核心场景,构建面向流程工业"机理数据"双轮驱动的领域计算层,推动AI for Science在材料化学领域的深度应用。 项目地…

2026/7/4 7:14:59 阅读更多 →
NCSN项目结构全解析:从配置文件到四大Runner类的使用指南

NCSN项目结构全解析:从配置文件到四大Runner类的使用指南

NCSN项目结构全解析:从配置文件到四大Runner类的使用指南 【免费下载链接】ncsn Noise Conditional Score Networks (NeurIPS 2019, Oral) 项目地址: https://gitcode.com/gh_mirrors/nc/ncsn Noise Conditional Score Networks(NCSN)…

2026/7/4 7:14:59 阅读更多 →

日新闻

Memcached 1.6.43 发布:关键安全修复版本,多项问题得到解决

Memcached 1.6.43 发布:关键安全修复版本,多项问题得到解决

Memcached 1.6.43 正式发布,这是一个关键的安全修复版本,修复了多个方面的问题,还对部分功能进行了优化。 安全修复亮点 此次发布在安全修复上表现突出。binprot 避免了项目引用计数溢出,mcmc 因安全问题提升了上游版本号&#xf…

2026/7/4 0:04:29 阅读更多 →
终极指南:使用HMCL启动器跨平台畅玩Minecraft的完整解决方案

终极指南:使用HMCL启动器跨平台畅玩Minecraft的完整解决方案

终极指南:使用HMCL启动器跨平台畅玩Minecraft的完整解决方案 【免费下载链接】HMCL A Minecraft Launcher which is multi-functional, cross-platform and popular 项目地址: https://gitcode.com/gh_mirrors/hm/HMCL HMCL(Hello Minecraft! Lau…

2026/7/4 0:06:29 阅读更多 →
KMX63与PIC18F66K40在嵌入式HMI中的硬件协同与低功耗设计

KMX63与PIC18F66K40在嵌入式HMI中的硬件协同与低功耗设计

1. KMX63与PIC18F66K40的硬件协同架构解析KMX63作为一款三轴加速度计和磁力计组合传感器,与PIC18F66K40微控制器的搭配堪称嵌入式HMI开发的黄金组合。这套硬件组合的核心优势在于KMX63提供的高精度运动感知能力与PIC18F66K40强大的信号处理能力形成了完美互补。KMX6…

2026/7/4 0:06:29 阅读更多 →

周新闻

月新闻