@Configuration @ConfigurationProperties(ignoreUnknownFields =true) @Component("testConfig ") public class testConfig { private Map<String,String> testKey = new HashMap<>(); public Map<String, String> gettestKey () { return testKey ; } public void settestKey (Map<String, String> testKey ) { this.testKey = testKey ; } @Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); yaml.setResources(new ClassPathResource("xx.yml"));//class引入 configurer.setProperties(yaml.getObject()); return configurer; } }
springboot加载自定义的yml文件内容
最新推荐文章于 2024-08-21 16:25:47 发布