首页 > 编程语言 > 详细

SpringBoot读取配置文件(从classpath/file读取yml/properties文件)

时间:2018-05-09 15:41:50      阅读:1888      评论:0      收藏:0      [点我收藏+]
一、读取properties文件
使用配置项@PropertySource
 
二、读取yml文件
启动类添加下面代码:
 
@Bean
public static PropertySourcesPlaceholderConfigurer properties() {
    PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
    YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
    yaml.setResources(new FileSystemResource("/dir/application.yml"));//File引入
    //yaml.setResources(new ClassPathResource("application.yml"));//class引入
    configurer.setProperties(yaml.getObject());
    return configurer;
}
 

 

1、引入多个配置文件:yaml.setResources(new ClassPathResource("application1.yml"), new ClassPathResource("application2.yml"));
 

 

  

SpringBoot读取配置文件(从classpath/file读取yml/properties文件)

原文:https://www.cnblogs.com/gossip/p/9014616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!