一、新建一个maven 工程

二、在pom.xml文件中加入如下依赖

4.0.0

com.bt.com.cn

bt-springboot

0.0.1-SNAPSHOT

bt-springboot

bt-springboot

org.springframework.boot

spring-boot-starter-parent

2.0.5.RELEASE

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-maven-plugin

三、在src/main/resources下新建如下文件

内容分别

application-dev.properties

application-prd.properties

application-test.properties

appliction.properties

其中application.properties中spring.profiles.active=prd  prd 为上面想要读文件的后一部分文件名

四、编写启动类

package com.batian;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

public class App {

public static void main(String[] args) {

SpringApplication.run(App.class, args);

}

}

四、编写一个controller

package com.batian.controller;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

@RestController

public class HttpController {

@Value("${httpUrl}")

private String httpUrl;

@RequestMapping("/getHttpUrl")

public String getHttpUrl(){

return httpUrl;

}

}

五、分别修改application.properties中spring.profiles.active=prd

1、当spring.profiles.active=prd  执行结果如下

2.当spring.profiles.active=test

3、当spring.profiles.active=dev

此时已实现不同环境下读取不同的配置文件

springboot获取active_springboot 使用spring.profiles.active 区分不同环境下配置文件相关推荐

  1. spring.profiles.active 多种开发环境配置详解

    在项目开发中,会有这样的需求,存在多种开发环境的配置,例如开发环境,预发环境,线上环境. 我们可以使用Spring的profiles机制来解决这种问题. Spring的profiles有两个变量我们可 ...

  2. SpringBoot配置文件中spring.profiles.active配置详解

    SpringBoot配置文件中spring.profiles.active配置详解 1.多环境配置 我们在开发Spring Boot应用时,通常同一套程序会被应用和安装到几个不同的环境,比如:开发.测 ...

  3. spring.profiles.include 跟 spring.profiles.active 的区别

    spring.profiles.include 跟 spring.profiles.active 的区别 背景 我们经常看到springboot的 spring.profiles.active,有时也 ...

  4. spring.profiles.active配置解析、

    1.在配置springcloud 时候.不了解spring.profiles.active 有什么作用.看看文档去了只有. > 查看官方文档: 2.1 Environment Repositor ...

  5. Springboot配置文件-spring.profiles.active

    Springboot配置文件-spring.profiles.active 配置文件中spring.profiles.active是区分不同环境的配置文件. 一个springBoot项目生成会经历开发 ...

  6. springboot:spring.profiles.active

    使用maven-install命令导出jar包. 使用 "java -jar jar包名称" 运行jar包 java -jar   springbootmvcproject-0.0 ...

  7. springboot启动spring.profiles.active和spring.profiles.include影响的区别

    application.properties文件内容 spring.profiles.active=test4 pring.profiles.include=test3,test5 version=1 ...

  8. springBoot配置spring.profiles.active多环境

    spring.profiles.active多环境配置 springBoot动态配置多环境(dev/test/prod)数据信息读取 pom文件配置 YAML文件配置 springBoot动态配置多环 ...

  9. springboot --spring.profiles.active=test 不生效

    在springboot项目中,运行jar包时使用 java -jar xxx.jar --spring.profiles.active=test ,但是并没有走bootstrap-test.yml文件 ...

最新文章

  1. 安利Mastodon:属于未来的社交网络
  2. 开发日记-20190915 关键词 汇编语言王爽版 第十三章
  3. PLSQL_数据泵Datapump导入导出数据IMPDP / EXPDP(概念)(Oracle数据导入导出工具)(转)...
  4. Java 最多能买到的笔数
  5. python类方法继承_对python中类的继承与方法重写介绍
  6. 【C语言简单说】十八:二维数组
  7. 查看list的形状_用Wordcloud生成指定形状的词云图
  8. 新浪微博php7升级实践,PHP7线上system time飙高问题
  9. scala中的apply方法与unapply方法
  10. 图像像素点赋值_OpenCV学习笔记(二)之图像阈值化
  11. 安装Fortran语言编程环境全流程记录
  12. 自强学堂mysql_Django ——自强学堂学习笔记
  13. 一文搞定java面试相近词的辨析
  14. 视频矩阵的作用及原理
  15. 附录E-分贝(dB和dBm)的理解
  16. html特效代码 枫叶,经典FLASH特效代码
  17. Ubuntu测试使用速腾RS-Lidar-16
  18. 【目标检测】批量裁剪图片小脚本
  19. 爱思助手安卓能用吗_更好用的Windows版签名工具来啦,操作非常简单,无需越狱!...
  20. makefile中函数subst函数

热门文章

  1. 转稚晖军大佬 --【自制FOC驱动器】深入浅出讲解FOC算法与SVPWM技术
  2. 特斯拉、蔚来、小鹏三款主流智能驾驶产品测评
  3. 三角肌前束(06):阿诺德推举
  4. ie6和ie7同时安装在一台电脑上的方法(附 IE 7.0 BETA3 绿色免安装版下载)
  5. 调用照相机和相册功能
  6. 3min初识ListView(4)-inflate打气筒实现复杂布局
  7. 百度智能云数据众包,更安全、更优质的数据能力,打造自动驾驶超智“双眼”...
  8. 精益生产之MES制造执行系统
  9. RVIZ可视化rosbag雷达数据
  10. 计算机绘画小房子教案,可爱的小房子──《画方形和圆形》教学案例