赞
踩
使用@PropertySource注解的同时,另外通过自定义PropertySourcesPlaceholderConfigurer实例将其配置信息暴露给spring environment,具体代码如下:
- @Bean
- public static PropertySourcesPlaceholderConfigurer properties()
- {
- PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
- YamlPropertiesFactoryBean yml = new YamlPropertiesFactoryBean();
- //引入自定义的yml配置文件,暴露给spring environment
- yml.setResources(new FileSystemResource("src/main/resources/yml/my.yml"));
- configurer.setProperties(yml.getObject());
- return configurer;
- }
使用springboot读取自定义配置的代码例子如下:
https://github.com/ingorewho/springboot-develope/tree/master/springboot-config
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。