spring.profiles.active=@profiles.active@ 的使用
现在在的公司用
spring.profiles.active=@profiles.active@
当我看到这个的时候,一脸蒙蔽,这个@
是啥意思。
这里其实是配合 maven profile
进行选择不同配置文件进行开发
实战
1.构建一个springboot 项目
这里使用idea进行构建的,这个过程省略
2.pom文件配置
<profiles>
<profile>
<!-- 生产环境 -->
<id>prod</id>
<properties>
<profiles.active>prod</profiles.active>
</properties>
</profile>
<profile>
<!-- 本地开发环境 -->
<id>dev</id>
<properties>
<profiles.active>dev</profiles.active>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<!-- 测试环境 -->
<id>test</id>
<properties>
<profiles.active>test</profiles.active>
</properties>
</profile>
</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
/**
* @author kevin
* @date 2019/6/28 16:12
*/
@RestController
public class HelloController {
@Value("${name}")
private String name;
@RequestMapping(value = {"/hello"},method = RequestMethod.GET)
public String say(){
return name;
}
}
5.启动测试
使用idea工具启动开发
默认是dev,假如想要使用prod配置文件,如上图选择prod,注意下面的导入,重启项目
D:\dev_code\profiles-demo\target>curl http://localhost:8080/hello
"prod"
6 打包
这里使用idea打包不再介绍,如果你使用命令
mvn clean package -P dev
则是使用dev配置
好了,玩的开心
转载于:https://www.cnblogs.com/zhenghengbin/p/11103998.html
spring.profiles.active=@profiles.active@ 的使用相关推荐
- java.profile.active,spring.profiles.active=@profiles.active@的含义
spring.profiles.active=@profiles.active@ ,其实是配合 maven profile进行选择不同配置文件进行启动. 当执行 mvn clean package - ...
- Active Spring transaction synchronization or active JTA transaction with specifi
1,写了一个保存日志方法,在无事务方法体里执行. 2,使用hibernate的save方法保存时报错 java.lang.IllegalStateException: Active Spring tr ...
- Active/Active与Active/Passive
转: 问:Active/Active与Active/Passive阵列之间的区别是什么?哪一种技术更好? 答: 拥有两个或者更多控制器的存储阵列(SCSI,FC,iSCSI以及NAS)可以配置成为Ac ...
- spring boot maven profiles,打包不同的配置文件
1. 在pom.xml添加 <profiles><profile><id>dev</id><properties><environme ...
- spring.profiles.active配置解析、
1.在配置springcloud 时候.不了解spring.profiles.active 有什么作用.看看文档去了只有. > 查看官方文档: 2.1 Environment Repositor ...
- spring.profiles.include 跟 spring.profiles.active 的区别
spring.profiles.include 跟 spring.profiles.active 的区别 背景 我们经常看到springboot的 spring.profiles.active,有时也 ...
- spring boot + maven使用profiles进行环境隔离
Spring Profile Spring可使用Profile决定程序在不同环境下执行情况,包含配置.加载Bean.依赖等. Spring的Profile一般项目包含:dev(开发), test(单元 ...
- 什么是Spring Profiles以及如何使用
[版权申明] 非商业目的注明出处可自由转载 出自:shusheng007 文章目录 概述 Profile是什么 如何使用 配置文件 代码配置 如何激活 使用启动参数 使用application配置文件 ...
- 图文细描:Maven Profiles 与 Spring Profiles 多环境配置
目录 前言 Spring Profiles使用 Maven Profiels使用 Spring Profiles和 Maven Profiles结合配置来打包 注意 前言 在项目开发过程中,我们离不开 ...
最新文章
- spring boot 文件上传工具类(bug 已修改)
- min-height最小高度的实现(兼容IE6、IE7、FF)
- Paper之CV:《One Millisecond Face Alignment with an Ensemble of Regression Trees》的翻译与解读
- oracle 10 数据库覆盖
- 为什么 ++[[]][+[]]+[+[]] = 10 ?
- HIBERNATE与 MYBATIS的对比
- 努力就一定会成功,这或许是一个问题?
- python下载网页内容_使用selenium下载整个html页面内容
- svn服务端安装、迁移教程、Eclipse切换svn连接库
- 素数筛(埃氏筛、欧拉筛)
- 【论文解读 KDD 2018 | PME】PME: Projected Metric Embedding on Heterogeneous Networks for Link Prediction
- pcb板led正负极图形_晶体二极管正负极判断_晶体二极管图形符号
- 家用双千兆路由器推荐_千兆以上(专业级)无线路由器路由器哪款好
- android 渠道包 作用,谈谈我的Android多渠道打包方式
- Android iOS防录屏截屏
- 我们无法创建新分区。【错误:0x80042468】
- 哪个配件最爱坏?电脑配件寿命浅谈
- kingcms php 下载,KingCMS企业版(PHP) v6.1.1641(Sp2)
- 【c++】string类的模拟实现(下)
- 非常精美的唐诗,无与伦比哦遥知兄弟登高处,遍插茱萸少一人。秦时明月汉时关,万里长征人未还。但使龙城飞将在,不教胡马度阴山。春眠不觉晓,处处闻啼鸟。夜来风雨声,花落知多少。君自故乡来,应知故乡事。来日绮