最近在spring boot项目中用到了yaml文件来作为conf配置,中间踩了一些坑,这里记录一下:
1. 自定义yaml配置的加载
首先,我的新增配置不在application.yaml
文件中,是单独拆出来放在子目录下的配置,首要任务是需要spring boot能够找到并成功加载,这里需要用到一个方法:
@Configuration
public class ConfManager {
@Bean
public static PropertySourcesPlaceholderConfigurer serviceConfig() {
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();