zoukankan      html  css  js  c++  java
  • SpringBoot读取配置文件(从classpath/file读取yml/properties文件)

    一、读取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"));
     

     

      

  • 相关阅读:
    jQuery-css
    了解jQuery
    jQuery属性
    jQuery常用效果
    jQuery_$工具方法
    jQuery选择器
    jQuery核心对象
    $
    jQuery两把利器
    JavaScriptDOM
  • 原文地址:https://www.cnblogs.com/gossip/p/9014616.html
Copyright © 2011-2022 走看看