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

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")。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值