springboot @PropertySource
@ConfigurationProperties(prefix="person") 默认加载全局配置文件 application.properties或application.yml
application.properties文件中有字段 persion.first-name
@PropertySource 加载指定路径的配置文件信息
application.properties同级目录有person.properties first-name 如读取person.properties需要加@PropertySource 注解并指定路径@PropertySource(value = { "classpath:person.properties" })
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component; @Component
@PropertySource(value = { "classpath:person.properties" })
@ConfigurationProperties(prefix="person")
public class Person { private String firstName; }
@ImportResource:导入Spring的配置文件,让配置文件里面的内容生效 (@importResource标注在一个配置类上)
@ImportResource(location={"classpath:xxx.xml"})
导入spring的配置文件让其生效
@Configuration:指明当前类是一个配置类;就是来替代之前的Spring配置文件;在配置文件中用<bean><bean/>标签添加组件
springboot推荐给容器中添加组件的方式:推荐使用全注解方式
1、配置类 相当于spring配置文件
2.使用@Bean 给容器添加组件
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration
public class MyAppConfig { //将方法的返回值添加到容器中;容器中这个组件默认的id就是方法名
@Bean
public HelloService helloService(){
return new HelloService();
}
}
springboot @PropertySource的更多相关文章
- Spring Boot外部化配置实战解析
一.流程分析 1.1 入口程序 在 SpringApplication#run(String... args) 方法中,外部化配置关键流程分为以下四步 public ConfigurableAppli ...
- SpringBoot入门教程(十八)@value、@Import、@ImportResource、@PropertySource
Spring Boot提倡基于Java的配置.这两篇博文主要介绍springboot 一些常用的注解介绍 v@value 通过@Value可以将外部的值动态注入到Bean中. 添加applicatio ...
- Spring-boot中@ConfigurationProperties,@Value,@PropertySource
1.利用@ConfigurationProperties获取配置的值,@ConfigurationProperties是springboot提供的基于安全类型的配置放置. application.pr ...
- SpringBoot标签之@ConfigurationProperties、@PropertySource注解的使用
当获取主配置文件中属性值时,只需@ConfigurationProperties(prefix = "person")注解来修饰某类,其作用是告诉springBoot,此类中的属性 ...
- SpringBoot配置——@PropertySource、@ImportResource、@Bean
@PropertySource:加载指定的配置文件 package com.hoje.springboot.bean; import org.springframework.beans.factory ...
- 3springboot:springboot配置文件(配置文件、YAML、属性文件值注入<@Value、@ConfigurationProperties、@PropertySource,@ImportResource、@Bean>)
1.配置文件: springboot默认使用一个全局配置文件 配置文件名是固定的 配置文件有两种(开头均是application,主要是文件的后缀): ->application.prope ...
- SpringBoot 配置 @PropertySource、@ImportResource、@Bean
一.@PropertySource @PropertySource:加载指定的配置文件 @PropertySource(value = {"classpath:person.properti ...
- SpringBoot自定义注解@YamlPropertySource加载yml或者yaml文件(扩展了@PropertySource)
1:概述 SpringBoot的@PropertySource注解只支持加载 properties结尾的文件.当使用@ConfigurationProperties 注解配合@EnableConfig ...
- SpringBoot源码学习系列之@PropertySource不支持yaml读取原因
然后,为什么@PropertySource注解默认不支持?可以简单跟一下源码 @PropertySource源码: 根据注释,默认使用DefaultPropertySourceFactory类作为资源 ...
随机推荐
- 关于 Azure Windows VM 的磁盘和 VHD
就像其他任何计算机一样,Azure 中的虚拟机将磁盘用作存储操作系统.应用程序和数据的位置. 所有 Azure 虚拟机都至少有两个磁盘,即 Windows 操作系统磁盘和临时磁盘. 操作系统磁盘基于映 ...
- Oracle EBS OM 已存在的OM订单增加物料
DECLARE l_header_rec OE_ORDER_PUB.Header_Rec_Type; l_line_tbl OE_ORDER_PUB.Line_Tbl_Type; l_action_r ...
- poj_3253 Fence Repair
Fence Repair Description Farmer John wants to repair a small length of the fence around the pasture. ...
- 从MySQL slave system lock延迟说开去
本文主要分析 sql thread中system lock出现的原因,但是笔者并明没有系统的学习过master-slave的代码,这也是2018年的一个目标,2018年我都排满了,悲剧.所以如果有错误 ...
- GridBagLayout布局管理器应用详解
http://www.cnblogs.com/kungfupanda/p/7220217.html GridBagLayout布局管理器应用详解 很多情况下,我们已经不需要通过编写代码来实现一个应用程 ...
- 团队作业8--测试与发布(Beta阶段)
展示博客 一.项目成员: 张慧敏(组长)201421122032 苏晓薇(组员)201421031033 欧阳时康(组员)201421122050 团队仓库: https://git.coding.n ...
- python 使用csv 文件写入 出现多余空行数据解决方案
因为csv.writerow() 方法会造成读取时每条数据后多一条空数据 解决方案如下: 分为两种情况 python2 和 python3 先说python2版本 with open('xxx.csv ...
- JAVA-最常用的A题语法
输出 System.out.println(""); if 语句 if(布尔表达式) { //如果布尔表达式为true将执行的语句 } if...else... 语句 if(布尔表 ...
- ATP学姐的模拟赛
ATPの水题大赛 声明:不是我觉得这题水,这就是本场模拟赛的名称. T1:求所有的$n$位数中有几个数满足:每一位要么是$A$要么是$B$,并且这个$n$位数的每一位加起来是$A$或$B$的倍数. $ ...
- 天地图api地址
天地图地址 http://lbs.tianditu.com/api-new/examples.html 参考资料 http://lbs.tianditu.com/api-new/class.html