自定义配置文件

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. 虚树(Bzoj3611: [Heoi2014]大工程)

    题面 传送门 虚树 把跟询问有关的点拿出来建树,为了方便树\(DP\) 在\(LCA\)处要合并答案,那么把这些点的\(LCA\)也拿出来 做法:把点按\(dfs\)序排列,然后求出相邻两个点的\(L ...

  2. JS实现省市联动效果

    实现的效果为:当选择一个省的时候,会自动出现该省下的市级 效果图如下: <body> <div> <!--界面展示--> <span>省份:</s ...

  3. VUE配置项结构

    VUE配置项结构 config:项目的配置文件 index.js: 基础的配置信息 dev.env.js:开发环境配置信息 prod.env.js:线上环境配置信息 build: 项目打包所需要的内容 ...

  4. git分支无法获取

    git 上新建的分支,本地想要拉取该分支,但是找不到这个分支 使用  git branch -a  也看不到该分支 使用命令: git checkout -b branch_nameA origin/ ...

  5. Spring Data MongoDB 分页查询

    在上篇文章 Spring Data MongoDB 环境搭建 基础上进行分页查询 定义公用分页参数类,实现 Pageable 接口 import java.io.Serializable; impor ...

  6. 然之协同系统6.4.1 SQL注入导致getshell

     前言 先知上一个大佬挖的洞,也有了简单的分析 https://xianzhi.aliyun.com/forum/topic/2135 我自己复现分析过程,漏洞的原理比较简单,但是漏洞的利用方式对我而 ...

  7. 【tips】编译epic异常解决

    目标:编译 epic 异常信息一: No CMAKE_C_COMPILER could be found.  No CMAKE_CXX_COMPILER could be found.   解决方法: ...

  8. 【眼见为实】自己动手实践理解数据库READ COMMITTED && MVCC

    [READ COMMITTED] 首先设置数据库隔离级别为读已提交(READ COMMITTED): set global transaction isolation level READ COMMI ...

  9. 把KB转化为KB及以上单位

    /** * 把KB转化为KB及以上单位 * @param int $kb * @return string $new_val */ function return_over_kb($kb) { $kb ...

  10. vue组件编写知识点