zoukankan      html  css  js  c++  java
  • spring 读取yaml配置文件

    从Spring框架4.1.0增加了对YAML的支持,Spring框架4.1.0 maven POM具有Snakeyaml依赖性  。

    您可以在Spring Boot应用中使用两种方式加载YAML:

    1、使用Java配置类

    复制代码
     @Bean
      public static PropertySourcesPlaceholderConfigurer properties() {
          PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
          YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
          yaml.setResources(new ClassPathResource("appConfig.yml");
          propertySourcesPlaceholderConfigurer.setProperties(yaml.getObject());
          return propertySourcesPlaceholderConfigurer;
      }
    复制代码

    2、使用XML Bean配置

    复制代码
    <context:annotation-config/>
     
    <bean id="yamlProperties" class="org.springframework.beans.factory.config.YamlPropertiesFactoryBean">
        <property name="resources" value="classpath:appConfig.yml"/>
    </bean>
     
    <context:property-placeholder properties-ref="yamlProperties"/>
    复制代码

    转自:https://www.cnblogs.com/EasonJim/p/7583837.html

  • 相关阅读:
    一个省一等奖没文件没证书,只能保存一张图呢
    HTML5的新结构标签
    一个最简单的网页是如何构成的
    数据模型层Model
    空控制器空操作
    TP框架
    thinkphp基础
    静态缓存
    smarty函数
    Smarty的使用
  • 原文地址:https://www.cnblogs.com/Gyoung/p/8663395.html
Copyright © 2011-2022 走看看