spring boot自定义读取配置文件

【spring boot自定义读取配置文件】建个文件
spring boot自定义读取配置文件
文章图片

在启动类

@Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); //yaml.setResources(new FileSystemResource("AlipayConfig.yml")); //File引入 yaml.setResources(new ClassPathResource("AlipayConfig.yml")); //class引入 configurer.setProperties(yaml.getObject()); return configurer; }

加载属性
spring boot自定义读取配置文件
文章图片

使用的 lombok.Data; 插件免去get,set

    推荐阅读