前提:
首先我确定我的yml配置文件里面配置没有错:
然后地址引用的地方也加了@Value,类上也加了@Service注解,引用的格式也没有错。
其次,我也试过了maven install,package,再三检查了target文件里面有配置文件,
发现都没有错 但是就是报错,
直接上干货:
解决方案有两种:
在配置文件里面,配置的地址没有和上一个地址空一行,需要间隔一行。如果还不行,使用下面的终极解决方案
配置占位符
@Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
PropertySourcesPlaceholderConfigurer placeholderConfigurer = new PropertySourcesPlaceholderConfigurer();
placeholderConfigurer.setIgnoreUnresolvablePlaceholders(true);
return placeholderConfigurer;
}