SpringBoot 解决多模块配置文件@Value()注解找不到配置文件问题解决方案
SpringBoot 解决多模块配置文件@Value()注解找不到配置文件问题解决方案
- 项目结构
启动模块为spi_wxcp, spi_ldap为ldap功能模块该模块为连接处理AD逻辑模块。
2. spi_ldap配置类信息
1 |
|
3.报错信息
1 | Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'wxCpConfiguration' defined in file [/Users/leslie/Desktop/Project/Spi_WxCP_Ldap/spi_wxcp/target/classes/com/spi/wxcp/config/WxCpConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 3; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'menuHandler': Unsatisfied dependency expressed through field 'ldapService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ldapServiceImpl': Unsatisfied dependency expressed through field 'ldapTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ldapConfig': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.ldap.urls' in value "${spring.ldap.urls} |
- 问题分析及解决方案
从报错信息看到是java.lang.IllegalArgumentException: Could not resolve placeholder ‘spring.ldap.urls’ in value “${spring.ldap.urls}”@value注解无法读取到配置文件,我们在配置类中声明了配置文件为application-ldap.yml,但是在多模块配置文件中除非为启动模块,使用@Value注解的读取的配置文件建议不要为yml格式,解决方法就是将配置文件yml改成properties文件即可。
修改后启动项目
没有报错配置文件注入成功
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 🤖!