自定义配置文件

my-config.properties

 bfxy.title=bfxy
bfxy.name=hello spring boot!
bfxy.attr=12345

配置文件类

appconfig.java

 import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment; @Configuration
@ComponentScan({"com.bfxy.springboot.*"}) //你要进行扫描的包路径
@PropertySource("classpath:my-config.properties") //加载指定的配置
public class appConfig { @Value("${custom.group}")
private String customGroup; @Autowired
private Environment environment; @Value("${bfxy.name}")
private String name; @Value("${bfxy.title}")
private String title; @Value("${bfxy.attr}")
private String attr; public void output(){
System.err.println("通过@Value注解读取配置: " + this.customGroup);
System.err.println("通过Environment对象读取配置: " + environment.getProperty("custom.team")); System.err.println("加载自己的配置文件内容"+this.name+","+this.title+","+this.attr);
} }

SpringBoot读取自定义配置文件的更多相关文章

  1. Springboot读取自定义配置文件的几种方法

    一.读取核心配置文件 核心配置文件是指在resources根目录下的application.properties或application.yml配置文件,读取这两个配置文件的方法有两种,都比较简单. ...

  2. springboot读取自定义配置文件节点

    今天和大家分享的是自定义配置信息的读取:近期有写博客这样的计划,分别交叉来写springboot方面和springcloud方面的文章,因为springboot预计的篇章很多,这样cloud的文章就需 ...

  3. Springboot 之 自定义配置文件及读取配置文件

    本文章来自[知识林] 读取核心配置文件 核心配置文件是指在resources根目录下的application.properties或application.yml配置文件,读取这两个配置文件的方法有两 ...

  4. Springboot 之 自定义配置文件及读取配置文件注意:配置文件中的字符串不要有下划线 .配置中 key不能带下划线,value可以(下划线的坑,坑了我两天..特此纪念)

    注意:配置文件中的字符串不要有下划线 .配置中  key不能带下划线,value可以 错误的.不能读取的例子: mySet .ABAP_AS_POOLED      =  ABAP_AS_WITH_P ...

  5. jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法

    jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法 用系统属性System.getProperty("user.dir")获得执行命令的目录(网上 ...

  6. SpringBoot读取外部配置文件的方法

    SpringBoot读取外部配置文件的方法 Spring高级之注解@PropertySource详解(超详细) 1.@PropertySource(value = {"classpath:c ...

  7. springboot读取自定义properties配置文件方法

    1. 添加pom.xml依赖 <!-- springboot configuration依赖 --> <dependency> <groupId>org.sprin ...

  8. springboot下自定义配置文件,并在项目里读取的方法

    首先 pom文件引入springboot文件处理器 <dependency> <groupId>org.springframework.boot</groupId> ...

  9. springboot读取外部配置文件

    springboot项目打成jar包后不好进行配置文件修改,可设置为读取外部配置文件,方便进行配置修改. 步骤: 1.将jar包中的application.properties配置文件复制到自定义路径 ...

随机推荐

  1. js组件开发-移动端地区选择控件mobile-select-area

    移动端地区选择控件mobile-select-area 由于之前的[js开源组件开发]js手机联动选择地区仿ios 开源git 很受欢迎,于是我又对其进行了一些优化,包括可选的范围变大了,添加了默认空 ...

  2. 自动生成了一本ES6的书

    ![WeChat_1462668550.jpeg](http://upload-images.jianshu.io/upload_images/1952818-7bd17a9dd6401dc6.jpe ...

  3. How To Secure Apache with Let's Encrypt on Ubuntu (Free SSL)

    Introduction This tutorial will show you how to set up a TLS/SSL certificate from Let's Encrypt on a ...

  4. QT开发(一)Vs2013集成 QT5.3.1

    原文:http://www.cnblogs.com/aoldman/p/3860837.html 很久不写随笔了,真是越来越懒.最近公司要做一款产品,想使用QT不用WPF lol,让苦逼的.net的我 ...

  5. EF Migrations

    Enable-Migrations -EnableAutomaticMigrations dbcontent Add-Migration XXXXX Update-Database -Verbose ...

  6. 修改maven默认的jdk版本

    修改maven默认的jdk版本,想改彻底需要在maven的全局配文件(settings.xml)增加以下信息:   在profiles 节点下增加: <profile> <id> ...

  7. 使用mathjax在博客中完美显示数学公式,支持PC,手机浏览器

    在博客园的设置选项里 有页头HTML的框内输入: <script type="text/javascript" src="http://cdn.mathjax.or ...

  8. golang开发不错的参考资料

    https://golangbot.com/learn-golang-series/ https://gist.github.com/ivangabriele/1c552aadc247c0a2f256 ...

  9. leetcode Ch1-Search

    一. Binary Search int binarySearch(vector<int> &array, int target) { , hi = array.size() - ...

  10. layui实现checkbox的目录树tree

    layui.use([ 'tree' ], function() {$ = layui.jquery;form = layui.form;//获取节点数据getTreeData();}); funct ...