在自定义配置中加入:
package com.cps.trans.route.configuration; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.io.ClassPathResource; /** * @author max woods * @date 2018/8/27 */ @Configuration //@ImportResource(locations = {"classpath:config/channel.yml","classpath:config/cups.yml"}) public class CustomConfiguration { @Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); // 从classpath导入 yaml.setResources(new ClassPathResource("/config/channel.yml"), new ClassPathResource("/config/cups.yml")); yaml.afterPropertiesSet(); configurer.setProperties(yaml.getObject()); return configurer; } }
- 本文固定链接: https://www.maxwoods.net/archives/1701
- 转载请注明: 第五维 于 第五维 发表