spring boot starter实现

示例

自定义线程池。

步骤

  1. 创建threadpool-spring-boot-starter工程

  1. 引入 Spring Boot 相关依赖

  1. 创建ThreadPoolAutoConfiguration

  1. threadpool-spring-boot-starter工程的 resources 包下创建META-INF/spring.factories文件。

  1. 新建工程引入threadpool-spring-boot-starter

  1. 调用

总结

Spring Boot 通过@EnableAutoConfiguration开启自动装配,通过 SpringFactoriesLoader 最终加载META-INF/spring.factories中的自动配置类实现自动装配,自动配置类其实就是通过@Conditional按需加载的配置类,想要其生效必须引入spring-boot-starter-xxx包实现初步依赖。

Last updated

Was this helpful?