Spring-Boot导入配置文件与取值
前言:
springboot简化了大量配置文件,但是必要时还是需要导入配置文件的,比如dubbo,此处简记之。
正文:
所有的配置文件引入都是使用注解在类上进行引入的,常用的有两种注解@PropertySource和@ImportSource,分别导入properties文件和xml文件
@PropertySource注解
引入单个properties文件:
@PropertySource(value = {"classpath : xxxx/xxx.properties"})
引入多个properties文件:
@PropertySource(value = {"classpath : xxxx/xxx.properties","classpath : xxxx.properties"})
@ImportSource注解 :可以额外分为两种模式 相对路径classpath,绝对路径(真实路径)file
注意:单文件可以不写value或locations,value和locations都可用
相对路径(classpath):
引入单个xml配置文件:
@ImportSource("classpath : xxx/xxxx.xml")
引入多个xml配置文件:
@ImportSource(locations={"classpath : xxxx.xml" , "classpath : yyyy.xml"})
绝对路径(file):
引入单个xml配置文件:
@ImportSource(locations= {"file : d:/hellxz/dubbo.xml"})
引入多个xml配置文件:
@ImportSource(locations= {"file : d:/hellxz/application.xml" , "file : d:/hellxz/dubbo.xml"})
取值:
使用@Value注解取配置文件中的值
@Value("${properties中的键}") private String xxx;
尾声:
如本文中有错误,还望评论告知一二,欢迎拍砖
Spring-Boot导入配置文件与取值的更多相关文章
- Spring Boot之配置文件值注入(@ConfigurationProperties)
前言:Spring Boot配置文件值的注入有两种方式,分别是 @ConfigurationProperties @Value 这里我们使用第一种 首先我们创建一个application.yml文件, ...
- Spring Boot(二) 配置文件
文章导航-readme 一.配置Spring Boot热部署 技术的发展总是因为人们想偷懒的心理,如果我们不想每次修改了代码,都必须重启一下服务器,并重新运行代码.那么可以配置一下热部署.有了 ...
- 关于spring boot项目配置文件的一些想法
一.springboot项目中有两种配置文件 springboot项目中有两种配置文件 bootstrap 和 application bootstrap是应用程序的父上下文,由父Spring App ...
- 一:Spring Boot 的配置文件 application.properties
Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...
- 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件 内容简介:本文介绍 Spring Boot 的配置文件和配置管理,以及介绍了三种读取配置文 ...
- Spring Boot 的配置文件application.properties
Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...
- Spring Boot属性配置文件:application.properties 详解
学习资料 网址 官方说明文档 https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-pro ...
- Spring Boot 核心配置文件 bootstrap & application
Spring Boot 核心配置文件 bootstrap & application 1.SpringBoot bootstrap配置文件不生效问题 2.bootstrap/ applicat ...
- spring boot全局配置文件优先级
前两篇介绍的application配置文件,即为spring boot全局配置文件.那么spring boot加载配置文件的时候,怎么确定加载哪个目录下哪个文件呢? spring boot默认的配置文 ...
随机推荐
- windows下远程访问Redis,windows Redis绑定ip无效,Redis设置密码无效,Windows Redis 配置不生效,Windows Redis requirepass不生效,windows下远程访问redis的配置
转载:http://fanshuyao.iteye.com/blog/2384074 一.Redis下载地址: https://github.com/MicrosoftArchive/redis/re ...
- C/S 和B/S 详解 --- 2017-04-25
来源:脚本之家 一.C/S 架构 1. 概念 C/S 架构是一种典型的两层架构,其全程是Client/Server,即客户端服务器端架构,其客户端包含一个或多个在用户的电脑上运行的程序,而服务器端有两 ...
- dhcp 的安装和配置文件
install: yum - y install dhcp modify : vim /etc/dhcp/dhcpd.conf ddns-update-style none;ignore cli ...
- Linux最佳的云存储服务分析
什么样的云服务才适合作为 Linux 下的存储服务?兄弟连www.itxdl.cn来帮大家分析一下! 大量的免费空间.毕竟,个人用户无法支付每月的巨额款项. 原生的 Linux 客户端.以便你能够方便 ...
- canvas动画气球
canvas小球的动画我用canvas画布实现的小球动画效果,可以参考下 我用canvas画布实现的小球动画效果,可以参考下 我用canvas画布实现的小球动画效果,可以参考下 我用canvas画布实 ...
- 使用angular-ui-router替代ng-router
angular框架自身提供的ng-route在一定程度上满足了我们的需求,但是他只针对于单视图,比如点击一个link跳转到另一个视图,但是在实际业务中,需要一个状态对应的视图中还包含其他的视图,或者一 ...
- Spring - JPA 一对一, 一对多, 多对多关联
现在有三个类:One Many Much One类 Much类 @Entity public class Much { @Id @GeneratedValue private Integer id; ...
- mybatis返回list
1 Model类 public class Vo { /** * this is used for receive data partly from table user_question_secti ...
- Logback.xml 给变量指定默认值
随着通用日志组件转入 Slf4j,logback 也变成了默认的日志实现,像 log4j 一样,logback.xml 中也可以使用系统属性或环境变量,如 ${catalina.home}.在 log ...
- Django——ORM
Object Relational Mapping(ORM) ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据 ...