前提原因:maven多模块中,使用@ConfigurationProperties加载启动模块中yml的配置信息,由于包扫描路径的原因,会获取不到yml信息。
参考链接:https://blog.csdn.net/xueyijin/article/details/124853073
现有yml文件

一、@ConfigurationProperties+@Component+spring.factories
配置类上加注解@ConfigurationProperties+@Component
在resource目录下创建 META-INF/spring.factories 文件,加入该配置类的权限类路径
二、@EnableConfigurationProperties
若需引入的模块中存在一些配置项需要配置,而spring.factories要写的项过多的话,则需要使用@EnableConfigurationProperties简化

=================简化写法==============
配置类

引入配置

引入上面模块的模块

本文介绍了在Maven多模块项目中使用@ConfigurationProperties加载yml配置信息的方法。通过两种方式实现:一是利用@Component注册并结合spring.factories文件指定配置类;二是采用@EnableConfigurationProperties简化配置过程。
1112

被折叠的 条评论
为什么被折叠?



