当前位置:   article > 正文

class path resource [application-dev.properties] cannot be opened because it does not exist.读取配置属性失败_class path resource [application.properties] canno

class path resource [application.properties] cannot be opened because it doe

class path resource [application-dev.properties] cannot be opened because it does not exist.读取配置属性失败

问题分析:SpringBoot启动时未能为配置类找到相应的配置文件!

问题原因: 

先看文件结构,文件树结构所致!

|--resource

     |--dev

          | --application-dev.properties

在配置类上加的注解(需要使用全路径)

@PropertySource("classpath:application-dev.properties") 

启动项目报上述错误!

方案一:此时修改注解即可,启动时能够正确加载配置(properties)

@PropertySource("classpath:/dev/application-dev.properties") 

方案二:application-dev.properties文件直接暴露在resource目录下,通过文件名区分不同的配置文件!

如果定义⼀个键值对 user.name=xxx ,在配置类或者@Component会读取不到对应写的属性值。为什么呢?Spring Boot 的默 认 StandardEnvironment ⾸先将会加载 “systemEnvironment" 作为⾸个PropertySource. ⽽ source 即 为System.getProperties().当 getProperty时,按照读取顺序,返回 “systemEnvironment" 的值.即 System.getProperty("user.name")。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/946606
推荐阅读
相关标签
  

闽ICP备14008679号