Spring-boot读取多个配置文件
来源:互联网 发布:php 使用ftp上传文件 编辑:程序博客网 时间:2024/06/04 23:39
由于工作原因,一个项目需要读取多个配置文件,经过网上一番搜索,成功实现目标,现将实现过程做如下记录,以供参考。
- 核心配置文件
resources 目录下有两个文件,声明下我项目的配置文件已放在git》> 上,bootstrap.properties 文件用已从git上获取我的配置文件,新建application-global.yml 文件用来做测试,文件目录如下
配置文件内容
在bootstrap.properties配置文件中通过spring.profiles.active属性来设置,其值对应{profile}值,如:spring.profiles.active=global就会加载application-global.yml 配置文件内容,具体如下所示:
spring.cloud.config.uri=http://spring.cloud.config.label=profilesspring.application.name=spring.cloud.config.profile=globalspring.profiles.active= global
程序启动会先浏览bootstrap.properties文件,然后获取git上配置文件启动,最后加载application-global.yml文件这样就实现多个配置文件同时读取。
application-global.yml配置文件内容如下:REG_USER_ACCOUNT_EXIST: "用户已注册"REG_SBK_ZC: "该社保卡已经被注册"
- 创建接口:
import io.swagger.annotations.Api;import io.swagger.annotations.ApiImplicitParam;import io.swagger.annotations.ApiOperation;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import org.springframework.core.env.Environment;@RestController@Api(description = "异常类")@RequestMapping("/global")public class GlobalController { @Autowired private Environment env; @ApiOperation(value = "异常名称") @ApiImplicitParam(name = "code", value = "异常编码", required = true, paramType = "query") @GetMapping("/code") public String code(@RequestParam String code) { return "message:"+env.getProperty(code); } }
启动程序,测试成功。
阅读全文
0 0
- Spring-boot读取多个配置文件
- Spring boot读取配置文件
- spring-boot 配置文件读取
- Spring boot 配置文件读取
- spring boot 读取配置文件
- spring boot mybatis 读取配置文件
- Spring boot读取配置文件总结
- spring boot mybatis 读取配置文件
- spring-boot中的读取配置文件
- java读取多个spring 配置文件
- 多个Spring配置文件时,读取方法
- spring boot 中配置文件的读取和多环境配置
- spring-boot读取props和yml配置文件
- spring-boot读取props和yml配置文件
- spring-boot读取props和yml配置文件
- spring-boot读取props和yml配置文件
- Spring boot之读取自定义配置文件
- spring-boot读取props和yml配置文件
- 数据结构实验之二叉树七:叶子问题
- PHPstorm中bootstrap3插件中cdn问题与thinkPHP中引入bootstrap笔记
- Android Fillder工具网络监测
- css实现右侧固定宽度,左侧宽度自适应
- ESP8266编译脚本之二
- Spring-boot读取多个配置文件
- 递归和循环两种方式实现未知维度集合的笛卡尔积
- 交叉编译知识简介
- Kafka的一些命令
- 单片机串口通信基础
- 程序员快速处理代码bug的5大技巧
- CentOS httpd的安装与简单设置
- 版本差异对比(五)-- 以JSON格式持久化文件MD5值至磁盘
- Android Studio出现Failed to open zip file问题的解决方法