weixin_45027536 2022-12-19 14:20 采纳率: 66.7%
浏览 162

springboot 注解@Value 注入配置文件的值报错

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"):没有效果

  • 写回答

3条回答 默认 最新

  • pzzhao 2022-12-19 14:27
    关注

    你没有用代码格式粘贴,所以看不出来你的yml配置文件那里是否有空格,你这个正常 webpath要比myconfig缩进两格才对,不知道是这里格式的问题,还是你确实也没有缩进。

    正常像下面这样配置就可以了

    myconfig:
      webpath: http://10.121.0.33
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 12月19日

悬赏问题

  • ¥15 请各位帮我看看是哪里出了问题
  • ¥15 vs2019的js智能提示
  • ¥15 关于#开发语言#的问题:FDTD建模问题图中代码没有报错,但是模型却变透明了
  • ¥15 uniapp的h5项目写一个抽奖动画
  • ¥15 hadoop中启动hive报错如下怎么解决
  • ¥15 如何优化QWebEngineView 加载url的速度
  • ¥15 关于#hadoop#的问题,请各位专家解答!
  • ¥15 如何批量抓取网站信息
  • ¥15 Spring Boot离线人脸识别
  • ¥15 使用Ant Design Pro vue的时候,使用环境变量的时候,构建报错是什么原因