springboot 注解@Value 注入配置文件值报错
springboot 注解@Value 注入配置文件值报错:Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'myconfig.webpath' in value "${myconfig.webpath}"
application.yml:
myconfig:
webpath: "http://10.121.0.33"
jgsj: "0 0 * * * ?"
XXService :
@Value("${myconfig.webpath}")
private String webpath;
Error creating bean with name 'compent': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fileDownloadService': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'myconfig.webpath' in value "${myconfig.webpath}"
我尝试解决方案:
1、检查拼写错误:通过复制查找方式,没有拼写错误
2、注释配置文件中其他的配置,因为之前简单的项目写个这个注解,不认为是配置文件的问题。
3、在Application里面加入注解@PropertySource(value="classpath:application.yml"):没有效果
你没有用代码格式粘贴,所以看不出来你的yml配置文件那里是否有空格,你这个正常 webpath要比myconfig缩进两格才对,不知道是这里格式的问题,还是你确实也没有缩进。
正常像下面这样配置就可以了
myconfig:
webpath: http://10.121.0.33
找到原因了是配置文件缓存,需要清楚缓存,清楚缓存的方法是先clean,再package.