[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
posted @ 2024-02-04 10:04  小天呜啦啦  阅读(192)  评论(0)    收藏  举报