前言:

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导入配置文件与取值的更多相关文章

  1. Spring Boot之配置文件值注入(@ConfigurationProperties)

    前言:Spring Boot配置文件值的注入有两种方式,分别是 @ConfigurationProperties @Value 这里我们使用第一种 首先我们创建一个application.yml文件, ...

  2. Spring Boot(二) 配置文件

    文章导航-readme 一.配置Spring Boot热部署     技术的发展总是因为人们想偷懒的心理,如果我们不想每次修改了代码,都必须重启一下服务器,并重新运行代码.那么可以配置一下热部署.有了 ...

  3. 关于spring boot项目配置文件的一些想法

    一.springboot项目中有两种配置文件 springboot项目中有两种配置文件 bootstrap 和 application bootstrap是应用程序的父上下文,由父Spring App ...

  4. 一:Spring Boot 的配置文件 application.properties

    Spring Boot 的配置文件 application.properties 1.位置问题 2.普通的属性注入 3.类型安全的属性注入 1.位置问题 当我们创建一个 Spring Boot 工程时 ...

  5. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件

    精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件 内容简介:本文介绍 Spring Boot 的配置文件和配置管理,以及介绍了三种读取配置文 ...

  6. Spring Boot 的配置文件application.properties

    Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...

  7. Spring Boot属性配置文件:application.properties 详解

    学习资料 网址 官方说明文档 https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-pro ...

  8. Spring Boot 核心配置文件 bootstrap & application

    Spring Boot 核心配置文件 bootstrap & application 1.SpringBoot bootstrap配置文件不生效问题 2.bootstrap/ applicat ...

  9. spring boot全局配置文件优先级

    前两篇介绍的application配置文件,即为spring boot全局配置文件.那么spring boot加载配置文件的时候,怎么确定加载哪个目录下哪个文件呢? spring boot默认的配置文 ...

随机推荐

  1. python文件基本操作(读,写,追加)

    一:只读(r) f=('d:\ python的联系文件'')   绝对路径和相对路径(绝对路径:能找到文件开始到结束路径,真实存在的路径,相对路径:在绝对路径一致的情况下新建一个文件) f=open( ...

  2. object转字符串

    1.obj.tostring() obj为空时,抛异常. 2.convert.tostring(obj) obj为空时,返回null: 3.(string)obj obj为空时,返回null:obj不 ...

  3. MMORPG中的相机跟随算法

    先上代码 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Cam ...

  4. 每个java初学者都应该搞懂的问题

    对于这个系列里的问题,每个学JAVA的人都应该搞懂.当然,如果只是学JAVA玩玩就无所谓了.如果你认为自己已经超越初学者了,却不很懂这些问题,请将你自己重归初学者行列.内容均来自于CSDN的经典老贴. ...

  5. elasticsearch------java操作之QueryBuilders构建搜索Query

    版权声明:本文为非原创文章,出处:http://blog.csdn.net/xiaohulunb/article/details/37877435. elasticsearch 分布式搜索系列专栏:h ...

  6. 剑指Offer-孩子们的游戏(圆圈中最后剩下的数)

    package Other; import java.util.LinkedList; /** * 孩子们的游戏(圆圈中最后剩下的数) * 每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友, ...

  7. 笔记:Spring Cloud Eureka 服务发现与消费

    服务发现与消费,其服务发现的任务是由Eureka的客户端完成,而服务的消费任务由Ribbon.JerseyClient等完成,Ribbon是一个基于HTTP和TCP的客户端负载均衡器:使用Jersey ...

  8. 笔记:Struts2 拦截器

    配置拦截器 Struts.xml 配置文件中,使用<interceptor-/>来定义拦截器,有属性 name 表示拦截器的名称,class 表示拦截器的具体首先类,可以使用<par ...

  9. poj-1207 THE 3n+1 problem

    Description Problems in Computer Science are often classified as belonging to a certain class of pro ...

  10. poj-1012-约瑟夫问题

    Description The Joseph's problem is notoriously known. For those who are not familiar with the origi ...