自定义yml文件 读取属性为null(两种解决方法)
读取models属性为null。
配置文件如下:
对应类如下:
使用了@PropertySource 指定classpath:application-specialness.yml,并没有起作用。
一、
通过springboot2中@ConfigurationProperties装载yml文件的时候调取出现值为null的解决办法和springboot 加载自定义yml文件(@PropertySource)了解到,@PropertySource默认不支持yml文件,需要新建类,继承DefaultPropertySourceFactory,重写createPropertySource方法。
二、
除此之外,还有一种方法。
配置spring.profiles.include属性
这样就可以直接读取到属性。
参考:
1、springboot 加载自定义yml文件(@PropertySource) 2、springboot2中@ConfigurationProperties装载yml文件的时候调取出现值为null的解决办法 3、springboot中spring.profiles.include的妙用
转载自:https://juejin.cn/post/6898591184940498951