SpringBoot读取自定义配置文件
自定义配置文件
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读取自定义配置文件的更多相关文章
- Springboot读取自定义配置文件的几种方法
一.读取核心配置文件 核心配置文件是指在resources根目录下的application.properties或application.yml配置文件,读取这两个配置文件的方法有两种,都比较简单. ...
- springboot读取自定义配置文件节点
今天和大家分享的是自定义配置信息的读取:近期有写博客这样的计划,分别交叉来写springboot方面和springcloud方面的文章,因为springboot预计的篇章很多,这样cloud的文章就需 ...
- Springboot 之 自定义配置文件及读取配置文件
本文章来自[知识林] 读取核心配置文件 核心配置文件是指在resources根目录下的application.properties或application.yml配置文件,读取这两个配置文件的方法有两 ...
- Springboot 之 自定义配置文件及读取配置文件注意:配置文件中的字符串不要有下划线 .配置中 key不能带下划线,value可以(下划线的坑,坑了我两天..特此纪念)
注意:配置文件中的字符串不要有下划线 .配置中 key不能带下划线,value可以 错误的.不能读取的例子: mySet .ABAP_AS_POOLED = ABAP_AS_WITH_P ...
- jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法
jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法 用系统属性System.getProperty("user.dir")获得执行命令的目录(网上 ...
- SpringBoot读取外部配置文件的方法
SpringBoot读取外部配置文件的方法 Spring高级之注解@PropertySource详解(超详细) 1.@PropertySource(value = {"classpath:c ...
- springboot读取自定义properties配置文件方法
1. 添加pom.xml依赖 <!-- springboot configuration依赖 --> <dependency> <groupId>org.sprin ...
- springboot下自定义配置文件,并在项目里读取的方法
首先 pom文件引入springboot文件处理器 <dependency> <groupId>org.springframework.boot</groupId> ...
- springboot读取外部配置文件
springboot项目打成jar包后不好进行配置文件修改,可设置为读取外部配置文件,方便进行配置修改. 步骤: 1.将jar包中的application.properties配置文件复制到自定义路径 ...
随机推荐
- Windows安装ActiveMQ记录
1.下载压缩包(activeMQ应用要基于jdk服务上,安装本软件时,最好已经安装了jdk并且配置好了环境变量) 下载5.12.2版本:http://activemq.apache.org/activ ...
- React+antd 在限制高度内实现滚动显示多个组件(show scrolled components in a limited height with react antd)
效果: 代码: import React from 'react'; import { Table } from 'antd'; import DatePicker1 from './DatePick ...
- 搭建VueMint-ui框架
搭建VueMint-ui框架 2018年01月07日 22:29:58 阅读数:2660 vueweb vue project 检查项目环境 一.检查是否安装node.js # 检查node版本 $ ...
- HTTP(S)网络框架的设计
0.麻烦 操作系统提供的网络接口都会令人不爽,要么太接近底层而使用不便,要么层次过高又不提供底层点的接口供设置参数.但是我们不能期望系统API做得很高级,因为没有绝对合适的网络库,必须定制化从而达到适 ...
- Phoenix 映射 HBase + Maven
声明 本文基于 Centos6.x + CDH5.x 什么是Phoenix Phoenix的团队用了一句话概括Phoenix:"We put the SQL back in NoSQL&qu ...
- unzipping/Users/xq/.gradle/wrapper /dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zi
unzipping/Users/xq/.gradle/wrapper /dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zi ...
- Android ImageSpan的使用
编辑框中加图片 代码如下: mSubjectDetailView = (TextView) findViewById(R.id.subject_detail); CharSequence text = ...
- Java面试通关要点【问题汇总篇】
基础篇 基本功: 面向对象的特征 final, finally, finalize 的区别 int 和 Integer 有什么区别 重载和重写的区别 抽象类和接口有什么区别 说说反射的用途及实现 说说 ...
- 数据分析之scipy常用方法(五)
1 Scipy简介 Scipy依赖于Numpy Scipy提供了真正的矩阵 Scipy包含的功能:最优化.线性代数.积分.插值.拟合.特殊函数.快速傅里叶变换.信号处理.图像处理.常微分方程求解器等 ...
- Python 词频统计
利用Python做一个词频统计 GitHub地址:FightingBob [Give me a star , thanks.] 词频统计 对纯英语的文本文件[Eg: 瓦尔登湖(英文版).txt]的英文 ...