SpringBoot中的starter是一种非常重要的机制,能够抛弃以前繁杂的配置,将其统一集成进starter,应用者只需要在maven中引入starter依赖,SpringBoot就能自动扫描到要加载的信息并启动相应的默认配置。starter让我们摆脱了各种依赖库的处理,需要配置各种信息的困扰!
starter起步依赖
starter起步依赖是springboot一种非常重要的机制,
它打包了某些场景下需要用到依赖,将其统一集成到starter,
比如,
这就是一个starter,你可以把它看做一个外部外部项目,注意:是外部项目。
starter命名规则
springboot提供的starter以spring-boot-starter-x的方式命名,
自定义starter以x-spring-boot-starter的方式命名,
以区分springboot生态提供的starter。
自定义starter
new module
mystarter-spring-boot-starter
maven项目
添加依赖
load maven changes
simplebean
自动配置类
META-INF\spring.factories
在resources下创建META-INF\spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.duohoob.config.MyAutoConfiguration
在spring-boot-mytest中引入mystarter-spring-boot-starter
load maven changes
添加配置
在spring-boot-mytest的src/main/resources/application.properties中添加配置
通过@Autowired引用
启动访问
正文完