SpringBoot 常用读取配置文件的 3 种方法!( 三 )

Configuration类
@Configuration@EnableConfigurationProperties(L2CacheProperties.class)public class CacheRedisCaffeineAutoConfiguration {@Autowiredprivate L2CacheProperties l2CacheProperties;@Beanpublic RedisCaffeineCacheManager cacheManager() {return new RedisCaffeineCacheManager(l2CacheProperties.getConfig());}}测试
项目启动后,进行Debug打断点,看有木有注入到L2CacheProperties实体中

SpringBoot 常用读取配置文件的 3 种方法!

文章插图
通过上面截图就可以看出,所有application.yml配置数据,都已经在L2CacheProperties实体中,说明配置成功,获取也成功了 。
【SpringBoot 常用读取配置文件的 3 种方法!】

经验总结扩展阅读