springboot解析自定义yml
2020-01-11 16:01
2611 查看
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
springboot解析自定义yml
在实际项目开发中我们经常需要用到一些自定义配置,并且希望单独配置,方便维护,现在介绍下方式:
方式一手动加载
对于一些不变动的配置,写死在项目中维护,如下
然后在启动类中加载该配置
'''
public class AAApplication { public static void main(String[] args) { SpringApplication.run(RecommendApplication.class, args); } @Bean public static PropertySourcesPlaceholderConfigurer properties() { PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean(); yaml.setResources(new ClassPathResource("siteuid-config.yml")); configurer.setProperties(yaml.getObject()); return configurer; } }
注意:如果是启动配置是properties文件,这里是无法加载yml,需要将配置的siteuid-config.yml转成siteuid-config.properties
方式二集成springcloud config
集成springcloud config后,默认根据应用名加载,如果需要加载多配置,需要修改相关配置:
spring: application: name: quote profiles: active: dev cloud: config: profile: dev name: quote,siteuid-config enabled: true discovery: service-id: config-server enabled: true
相关文章推荐
- spring-boot读取自定义文件三:对于yml文件读取的解析
- SpringBoot如何导入自定义配置的yml文件
- spring boot装载自定义yml文件
- Spring boot 自定义注解 简单版本解析参数
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot下自定义参数绑定步骤解析
- SpringBoot如何导入自定义配置的yml文件
- spring boot 加载自定义yml
- Spring Boot 引入自定义yml
- springboot~yml里的自定义配置
- springboot 自定义yml 配置文件
- SpringBoot 的 yml文件 属性读取部分源码解析
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- Spring Boot自定义加载yml实现,附源码解读
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot如何导入自定义配置的yml文件
- SpringBoot自定义注解@YamlPropertySource加载yml或者yaml文件(扩展了@PropertySource)
- 笔记--Spring Boot中解析yml配置 注入到对象