springboot的精髓是自动依赖注入。那么哪些能自动注入呢,打开spring-boot-autoconfigure,jar下的spring.factories。
可以看到一堆这样的配置:
# Auto Configure org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\ org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\ org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\ org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\ org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,\
让我们随便点开一个文件,AopAutoConfiguration,

这里的就能看到我们能写在配置文件里的配置。
真正的加载原理在
SpringApplication.class这个类中,位于第138的run方法中,
createApplicationContext()这个方法进行加载。
本文深入探讨了SpringBoot自动依赖注入的原理,通过解析spring-boot-autoconfigure的spring.factories文件,揭示了AopAutoConfiguration等配置如何被自动加载。关键过程发生在SpringApplication的run方法中的createApplicationContext调用。

被折叠的 条评论
为什么被折叠?



