天天看点

关于application.yml配置读取

yml配置文件

在完成项目的过程中,遇到了这样一个问题:读取application.yml信息时,报空指针异常。

application.yml配置如下:

在自定义的 PropertiesUtil类中,进行了对resources下 application.yml配置文件的加载

但是当我在使用 PropertiesUtil.getProperty("cacheable.redis.ttl") 时,报错空指针异常,这让我有点摸不着头脑,就进行debug。

发现,在对 cacheable.redis.ttl 读取中key为 ttl

关于application.yml配置读取

因为key值不为 cacheable.redis.ttl ,所以肯定会报空指针异常。

因此我们在yml文件中读取配置信息时,需设置为

读取的时候才为:

关于application.yml配置读取

或者对调用方法的key值进行修改:

PropertiesUtil.getProperty("ttl") 

继续阅读