SpringBoot源码学习系列之@PropertySource不支持yaml读取原因
然后,为什么@PropertySource注解默认不支持?可以简单跟一下源码 @PropertySource源码: 根据注释,默认使用DefaultPropertySourceFactory类作为资源文件加载类 里面还是调用Spring框架底层的PropertiesLoaderUtils工具类进行读取的 PropertiesLoaderUtils.loadProperties 从源码可以看出也是支持xml文件读取的,能支持reader就获取reader对象,否则出件inputStream load0方法是关键,这里加了同步锁 很重要的load0 方法抓取出来: private void load0 (LineReader lr) throws IOException { char[] convtBuf = new char[1024]; int limit; // 当前key所在位置 int keyLen; // 当前value所在位置 int valueStart; char c;//读取的字符 boolean hasSep; boolean precedingBackslash;//是否转义字符,eg:/n etc. // 一行一行地读取 while ((limit = lr.readLine()) >= 0) { c = 0; keyLen = 0; valueStart =