spring-boot-starter实践

参见个人github

https://github.com/RLin2015New/spring-boot-starter-demo

注意点为:

1.xx-spring-boot-starter-autoconfigurer、xx-spring-boot-starter的命名规范,以及starter管理依赖,configurer负责具体实现的这种依赖解耦解构

2.自动配置类依赖于META-INF/spring.factories中的EnableAutoConfiguration相关的配置项

3.当前范例实现中通过@ConditionalOnMissingBean(IHelloConfigurationConfiguration.class)达成允许用户自定义配置实现

4.自动配置类加载机制可以通过SpringFactoriesLoader.loadFactoryNames来探听,主体思路为通过一系列复杂处理,从spring.factories中读取EnableAutoConfiguration配置,获取bean定义,然后在后续环节中统一做实例化的;如果有依赖注入,可能会被触发来做实例化(也就是说会提前实例化) 

5.范例中还追加了ApplicationContextInitializer、SpringApplicationRunListener、ApplicationRunner、CommandLineRunner的一个范例实现

猜你喜欢

转载自www.cnblogs.com/ybk2018af/p/12604195.html