现在在的公司用spring.profiles.active=@profiles.active@ 当我看到这个的时候,一脸蒙蔽,这个@ 是啥意思。

这里其实是配合 maven profile进行选择不同配置文件进行开发

实战

1.构建一个springboot 项目

这里使用idea进行构建的,这个过程省略

2.pom文件配置

  1. <profiles>

  2. <profile>

  3. <!-- 生产环境 -->

  4. <id>prod</id>

  5. <properties>

  6. <profiles.active>prod</profiles.active>

  7. </properties>

  8. </profile>

  9. <profile>

  10. <!-- 本地开发环境 -->

  11. <id>dev</id>

  12. <properties>

  13. <profiles.active>dev</profiles.active>

  14. </properties>

  15. <activation>

  16. <activeByDefault>true</activeByDefault>

  17. </activation>

  18. </profile>

  19. <profile>

  20. <!-- 测试环境 -->

  21. <id>test</id>

  22. <properties>

  23. <profiles.active>test</profiles.active>

  24. </properties>

  25. </profile>

  26. </profiles>

  • 这里默认dev配置

3.配置多个配置文件

application.properties

注意这里的profiles.active 要和pom文件的对应上

spring.profiles.active=@profiles.active@

application-dev.properties

name = "dev"

application-prod.properties

name = "prod"

application-test.properties

name = "test"

4.编写个测试的controller

  1. /**

  2. * @author kevin

  3. * @date 2019/6/28 16:12

  4. */

  5. @RestController

  6. public class HelloController {

  7. @Value("${name}")

  8. private String name;

  9. @RequestMapping(value = {"/hello"},method = RequestMethod.GET)

  10. public String say(){

  11. return name;

  12. }

  13. }

5.启动测试

使用idea工具启动开发

默认是dev,假如想要使用prod配置文件,如上图选择prod,注意下面的导入,重启项目

  1. D:\dev_code\profiles-demo\target>curl http://localhost:8080/hello

  2. "prod"

6 打包

这里使用idea打包不再介绍,如果你使用命令

mvn clean package -P dev

则是使用dev配置

好了,玩的开心

转载于:https://www.cnblogs.com/zhenghengbin/p/11103998.html

spring.profiles.active=@profiles.active@ 的使用相关推荐

  1. java.profile.active,spring.profiles.active=@profiles.active@的含义

    spring.profiles.active=@profiles.active@ ,其实是配合 maven profile进行选择不同配置文件进行启动. 当执行 mvn clean package - ...

  2. Active Spring transaction synchronization or active JTA transaction with specifi

    1,写了一个保存日志方法,在无事务方法体里执行. 2,使用hibernate的save方法保存时报错 java.lang.IllegalStateException: Active Spring tr ...

  3. Active/Active与Active/Passive

    转: 问:Active/Active与Active/Passive阵列之间的区别是什么?哪一种技术更好? 答: 拥有两个或者更多控制器的存储阵列(SCSI,FC,iSCSI以及NAS)可以配置成为Ac ...

  4. spring boot maven profiles,打包不同的配置文件

    1. 在pom.xml添加 <profiles><profile><id>dev</id><properties><environme ...

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

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

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

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

  7. spring boot + maven使用profiles进行环境隔离

    Spring Profile Spring可使用Profile决定程序在不同环境下执行情况,包含配置.加载Bean.依赖等. Spring的Profile一般项目包含:dev(开发), test(单元 ...

  8. 什么是Spring Profiles以及如何使用

    [版权申明] 非商业目的注明出处可自由转载 出自:shusheng007 文章目录 概述 Profile是什么 如何使用 配置文件 代码配置 如何激活 使用启动参数 使用application配置文件 ...

  9. 图文细描:Maven Profiles 与 Spring Profiles 多环境配置

    目录 前言 Spring Profiles使用 Maven Profiels使用 Spring Profiles和 Maven Profiles结合配置来打包 注意 前言 在项目开发过程中,我们离不开 ...

最新文章

  1. spring boot 文件上传工具类(bug 已修改)
  2. min-height最小高度的实现(兼容IE6、IE7、FF)
  3. Paper之CV:《One Millisecond Face Alignment with an Ensemble of Regression Trees》的翻译与解读
  4. oracle 10 数据库覆盖
  5. 为什么 ++[[]][+[]]+[+[]] = 10 ?
  6. HIBERNATE与 MYBATIS的对比
  7. 努力就一定会成功,这或许是一个问题?
  8. python下载网页内容_使用selenium下载整个html页面内容
  9. svn服务端安装、迁移教程、Eclipse切换svn连接库
  10. 素数筛(埃氏筛、欧拉筛)
  11. 【论文解读 KDD 2018 | PME】PME: Projected Metric Embedding on Heterogeneous Networks for Link Prediction
  12. pcb板led正负极图形_晶体二极管正负极判断_晶体二极管图形符号
  13. 家用双千兆路由器推荐_千兆以上(专业级)无线路由器路由器哪款好
  14. android 渠道包 作用,谈谈我的Android多渠道打包方式
  15. Android iOS防录屏截屏
  16. 我们无法创建新分区。【错误:0x80042468】
  17. 哪个配件最爱坏?电脑配件寿命浅谈
  18. kingcms php 下载,KingCMS企业版(PHP) v6.1.1641(Sp2)
  19. 【c++】string类的模拟实现(下)
  20. 非常精美的唐诗,无与伦比哦遥知兄弟登高处,遍插茱萸少一人。秦时明月汉时关,万里长征人未还。但使龙城飞将在,不教胡马度阴山。春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少。君自故乡来,应知故乡事。来日绮

热门文章

  1. 解决uni-app微信小程序IOS没声音
  2. 如何恢复回收站中被删除的文件?高效的恢复技巧
  3. centos命令行初始化配置
  4. Base64与Bitmap转换
  5. CMD命令格式化U盘(磁盘)
  6. 概述MOS管的结构知识、原理详解-KIA MOS管
  7. SpaceX将在菲律宾推出星链服务
  8. strtol 函数详解
  9. 一个依赖解决 Spring Boot 反爬虫,防止接口盗刷
  10. 思科交换机如何根据MAC地址查所在交换机的端口