Why use spring.factories for Spring Boot auto-configuration instead of annotations?

后端 未结 3 1757
感情败类
感情败类 2020-12-29 07:29

The documentation states:

Developing auto-configuration and using conditions

If you work in a company that develops shared libraries, or i

3条回答
  •  庸人自扰
    2020-12-29 08:07

    all the entries in spring.factories are loaded by below method -

    org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelector#loadFactoryNames

    protected Collection loadFactoryNames(Class source) {
            return SpringFactoriesLoader.loadFactoryNames(source, getClass().getClassLoader());
        }
    

    SpringFactoriesLoader belongs to the spring-core library see below screen shot

提交回复
热议问题