来源:blog.csdn.net/u011909918/article/details/109647196在前言中,我告诉你四大组件是:starter,autoconfigure,CLI和actuator。让我们仔细看看它们有什么用。一、SpringBootStarter1.1Starter应用实例org.mybatis.spring.bootmybatis-spring-boot-starter1.3.2SpringBoot的基础就不介绍了,还有这是推荐的实用教程:https://github.com/javastacks...在我们SpringBoot项目的POM文件中,总会看到这两个依赖:spring-boot-starter-xxx和xxx-spring-boot-开胃菜。这是springboot四大组件之一的starter。A。spring-boot-starter-thymeleafb和mybatis-spring-boot-starter的区别在于>>官方的starter是这样的:spring-boot-starter-xxx非官方的starter是这样的:xxx-spring-boot-starter其中xxx是我们要依赖的组件或jar包。上面的例子就是我们springboot配置的依赖,引入thymeleaf引擎和mybatis框架。引入后,通过简单的合约配置即可正常使用。例如:Thymeleaf引擎约定配置:##前端引擎配置spring:thymeleaf:enabled:trueservlet:content-type:text/htmlmode:HTML##pageprefixprefix:classpath:/templates/##suffixsuffix:.htmlMybatisconventionConfiguration:mybatis:mapper-locations:classpath:mapper/*.xml#注意:必须对应mapper映射xml文件的路径type-aliases-package:com.hi.ld.vo.system#注意:对应实体类Path配置:log-impl:org.apache.ibatis.logging.stdout.StdOutImpl让我们看看之前如何配置thymeleaf。1.2Thymeleaf和Mybatis在SpringBoot之前的应用废话不多说,直接上代码:1.2.1Thymeleaf配置a.添加对应依赖:org.thymeleafthymeleaf-spring53.0.11.RELEASEorg.thymeleaf.extrasthymeleaf-extras-java8time<版本>3.0。4.发布b.bean配置".html"/>1.2.2Mybatis配置添加对应的依赖:mybatisorg.mybatismybatis-springb.bean下面第3、4步是Mybatis-相关配置。第一步是引入资源配置。第二步配置数据源1.2.3总结a.Starter帮我们封装了所有需要的依赖,避免了一些Jar包冲突或者我们自己添加导致的漏包;b.Starter自动帮我们将需要的Bean实例注入到Spring容器中,无需手动配置(这个可以说是starter完成的,但实际上并没有完成。这里有个坑,下面解释回答);因此:starter包的内容就是pom文件,是一个依赖传递包2.SpringBootAutoconfigure2.1autoconfigure简介Autoconfigure在我们的开发中是不会被感知到的,因为它存在于我们的starter中。所以我们每个starter都依赖autoconfigure:当然我们也可以直接把autoconfig的内容放在starter包里。A。spring-boot-autoconfigure:注意:这里有一点,就是官网提供的configure大部分都在spring-boot-autoconfigure包中,并没有单独新建包。b.mybatis-spring-boot-autoconfigure2.2总结autoconfigure的内容是将Bean实例配置到Spring容器的实际代码实现包中,然后提供给starter依赖。所以,1.2.3的b项中提到的将Bean实例配置到Spring容器中,实际上是由autoconfigure完成的,因为starter依赖于它,所以也可以说是starter来做。因此:autocinfigure是starter所体现能力的代码实现3.SpringBootCLISpringBootCLI是一个在命令行使用SpringBoot的客户端工具;主要功能如下:运行groovy脚本=>官网2.1将groovy文件打包成jar=>官网2.3初始化SpringBoot项目=>官网2.4其他首先进入官网文档:https://docs。spring.io/spring...因为这个我们用的比较少,就不细说了。个人比较马虎的功能是直接在命令行执行groovy脚本。4、SpringBoot执行器Actuator是SpringBoot的一个监控插件,提供了很多接口获取当前项目的各种运行状态指标。官网文档:https://docs.spring.io/spring...名词解释:Endpoints:需要监控的端点。参考官网??第二部分官网文档的可用端点:web项目的端点如下。使用方法如下:4.1给SpringBoot添加依赖基础的就不介绍了,推荐这个实用教程:https://github.com/javastacks...org.springframework。boot>spring-boot-starter-actuator4.2配置需要监控的端点management:endpoint:health:##启用健康监控endpointenabled:truebeans:##启用Bean实例监控端点enabled:true4.3启动服务并验证4.3.1启动结果4.3.2查看各个监控信息浏览器访问(查看监控信息地址):http://localhost:9500/actuator查看服务健康状态:其他的API,查看官方文档了解一下或者留言一起研究下吧,没用到这个就厚脸皮了。但是在下一章介绍了starter和autoconfigure之后,我们就可以研究actuator的源码了。...小结本章主要介绍了SpringBoot的四大组件的功能,主要是starter和autoconfigure,其他的CLI和actuator用得不多,就不详细介绍了。近期热点文章推荐:1.1000+Java面试题及答案(2022最新版)2.厉害了!Java协程来了。..3.SpringBoot2.x教程,太全面了!4.20w程序员红包封面,快拿。..5.《Java开发手册(嵩山版)》最新发布,赶快下载吧!感觉不错,别忘了点赞+转发!