[SpringBoot]SpringBoot3.x版本下spring.factories无效,无法自动配置问题
问题
在SpringBoot2.x
版本下在res/META-INF/spring.factories
文件下定义
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.example.xxx.xxx.Xxx
可以实现自动配置注入,但是最近升级到3.x后这么定义发现无法生效于是排查原因
原因
根据org.springframework.boot.context.annotation.ImportCandidates
类中load(Class<?> annotation, ClassLoader classLoader)
方法得知
在SpringBoot3.x
中,默认不再是扫描META-INF/spring.factories
了,
而是META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
文件格式
一行一个全限定类名
[org.springframework.boot.autoconfigure.AutoConfiguration.imports]
com.example.xxx.Xxx
com.example.Yyyy.yyy