spring boot starter实现
示例
自定义线程池。
步骤
创建
threadpool-spring-boot-starter工程

引入 Spring Boot 相关依赖

创建
ThreadPoolAutoConfiguration

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

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

调用

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