[SpringBoot]SpringBoot3.x版本下spring.factories无效,无法自动配置问题
[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

浙公网安备 33010602011771号