赞
踩
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")。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。