springboot~3.x和spring.factories说拜拜了

在SpringBoot2.x版本下,公用包在resources/META-INF/spring.factories文件下定义

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.lind.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,这个在springboot 2.7以后的版中已经得到使用,但那边spring.factories还是可以用的。

com.lind.a
com.lind.b
com.lind.c

相关参考

posted @ 2025-05-28 16:06  张占岭  阅读(35)  评论(0)    收藏  举报