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
spring 读取yaml配置文件的更多相关文章
- spring读取prperties配置文件(2)
接上篇,spring读取prperties配置文件(1),这一篇主要讲述spring如何用annotation的方式去读取自定义的配置文件. 这里我先定义好属性文件"user.propert ...
- spring读取prperties配置文件(1)
博客地址http://www.cnblogs.com/shizhongtao/p/3438431.html 属性文件命名是*.properties,在java中,用类java.util.Propert ...
- python的logging模块之读取yaml配置文件。
python的logging模块是用来记录应用程序的日志的.关于logging模块的介绍,我这里不赘述,请参见其他资料.这里主要讲讲如何来读取yaml配置文件进行定制化的日志输出. python要读取 ...
- Spring Boot: Yaml配置文件 以及 @ConfigurationProperties属性获取
Yaml配置文件 概述 Spring Boot在支持application.properties配置文件的同时,也支持application.yaml配置文件. 配置文件中的属性,可以通过: 通过@V ...
- Spring读取xml配置文件的原理与实现
本篇博文的目录: 一:前言 二:spring的配置文件 三:依赖的第三方库.使用技术.代码布局 四:Document实现 五:获取Element的实现 六:解析Element元素 七:Bean创造器 ...
- python读取yaml配置文件
支持多种语言:python.js.golang.java.c.c++ YAML 语言(发音 /ˈjæməl/ )的设计目标,就是方便人类读写.它实质上是一种通用的数据串行化格式. 它的基本语法规则如下 ...
- spring读取xml配置文件(二)
一.当spring解析完配置文件名的占位符后,就开始refresh容器 @Override public void refresh() throws BeansException, IllegalSt ...
- python+Appium自动化:读取Yaml配置文件
Yaml简介 Yaml:"Yet Another Markup Language"(是一种标记语言),但为了强调这种语言以数据做为中心,而不是以标记语言为重点,而用反向缩略语重命名 ...
- Spring 读取XML配置文件的两种方式
import org.springframework.context.ApplicationContext; import org.springframework.context.support.Cl ...
随机推荐
- Scrapy爬取猫眼《复仇者联盟4终局之战》影评
一.分析 首先简单介绍一下Scrapy的基本流程: 引擎从调度器中取出一个链接(URL)用于接下来的抓取 引擎把URL封装成一个请求(Request)传给下载器 下载器把资源下载下来,并封装成应答包( ...
- Spring bean的生命流程
Spring 是一个轻量级的 J2EE 开源框架,其目标是降低企业级应用开发难度,提高企业级应用开发效率.在日程开发中,我们会经常使用 Spring 框架去构建应用.所以作为一个经常使用的框架,了解其 ...
- 20175325 《JAVA程序设计》实验一 《JAVA开发环境的熟悉》实验报告
20175325 <JAVA程序设计>实验一 <JAVA开发环境的熟悉>实验报告 一.实验内容及步骤 (一).实验一: 实验要求: 0 参考实验要求 1 建立"自己学 ...
- Python第十七天 抽象类
from abc import ABCMeta, abstractmethod class A(metaclass=ABCMeta): 称 A 为抽象类 @abstractmethod def tes ...
- hdfs数据采集场景示意图
- 三、PyQt5不同方法创建菜单栏、工具栏和状态栏
创建菜单栏.工具栏和状态栏可以直接通过代码实现,也可以通过Qt Designer中的属性编辑器等实现.通过两种方法的学习可以加深理解,更好的掌握PyQt5. 一.菜单栏与状态栏 状态栏的设置比较简单, ...
- AX_DataSource
for (custInvoiceJourLocal = custInvoiceJour_ds.getFirst(true) ? custInvoiceJour_ds.getFirst(true) : ...
- canvas简易画板。
在学canvas的时候,想到可以做一个自己用来画画的简易画板,加上canvas的基础都已经学完,便尝试做了一个画板.如图 1.获取标签. var c=document.getElementById(' ...
- 模块化jQuery的方法
首先有一个格式是这样的 require.config({ paths:{ 'jquery':'libs/jquery-3.1.1', 'swiper':'libs/swiper.js' }}); re ...
- bp代码
#电池老化率测定的神经网络模型 import tensorflow as tf import numpy as np import matplotlib.pyplot as plt import pa ...