spring.profiles.active=@profiles.active@的含义
spring.profiles.active=@profiles.active@ ,其实是配合 maven profile进行选择不同配置文件进行启动。
当执行
mvn clean package -P test 命令时, @profiles.active@ 会替换成 test
打开 jar包,即可看到:

实战
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配置
spring.profiles.active=@profiles.active@的含义的更多相关文章
- How to set spring boot active profiles with maven profiles
In the previous post you could read about separate Spring Boot builds for a local development machin ...
- SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用
现在在的公司用spring.profiles.active=@profiles.active@ 当我看到这个的时候,一脸蒙蔽,这个@ 是啥意思. 这里其实是配合 maven profile进行选择不同 ...
- java.lang.IllegalStateException: Active Spring transaction synchronization or active JTA transaction with specified [javax.transaction.TransactionManager] required
错误信息: java.lang.IllegalStateException: Active Spring transaction synchronization or active JTA trans ...
- spring boot配置项profiles active
结论:通用项配置在applicaton.yml,区别环境配置在application-{profile}.yml中 一直不知道这个参数要不要配,配了有什么用,今天搭一个工程来检验 此项作用:用来区分不 ...
- spring boot maven profiles,打包不同的配置文件
1. 在pom.xml添加 <profiles> <profile> <id>dev</id> <properties> <envir ...
- Spring Boot features - Profiles
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html https://w ...
- Spring Boot常用的注解以及含义<持续更新>
1.@RestController和@RequestMapping注解 @RestController 和 @RequestMapping 注解是Spring MVC注解(它们不是Spring Boo ...
- Spring学习之-各注解的含义总结
注解配置 @ComponentScan("spittr.web"):/在加载Spring上下文时,会扫描spittr.web包查找组件 @ComponentScan注解扫描的组件有 ...
- Spring 各种注解(@)的含义与认识
依赖注入,从字面上理解,即是:以注入的方式实现依赖: Spring 容器负责创建应用程序中的 bean,并通过 DI(依赖注入)来协调这些对象之间的关系.当描述 bean 如何进行装配(autowir ...
随机推荐
- C# 构造基础返回值类型-BaseResponse
学无止境,精益求精 十年河东,十年河西,莫欺少年穷 用于基础返回值类型,如下: using System; using System.Collections.Generic; using System ...
- JavaScript 总结[目录]
ECMAScript 基础 一.JavaScript 基础 1.1 JavaScript 简介 1.2 JavaScript 书写位置 二.JavaScript 数据类型 2.1 JavaScript ...
- QML MultiPointTouchArea
MultiPointTouchArea为qml中的多点触摸提供了最基本.最重要的支持,它与TouchPoint及相关域结合,可以说是qml中多点触摸的基石. MultiPointTouchArea是不 ...
- bugku——宽带信息泄露(RouterPassView 查看路由器配置信息)
题目地址:http://ctf.bugku.com/files/5986768ca8b96cead45aec16a88431b5/conf.bin 下载之后发现是个后缀名为bin的二进制文件,其实这个 ...
- Python的字符串与字节码转换
一张图弄懂python的字符串与字节码转换
- 使用Nginx对Websocket进行反向代理
一. Nginx配置示例 http { map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { li ...
- django modelformse批量编辑 查询学生班级成绩
复习先知 关于三张表的编辑学生成绩在跨表查询的对象查询种,只能通过找到两张表的关联的对象,进行跨表,就是在一对多或多对多的模型找到他们俩的class_id或student_id在关联时,会通过他们找到 ...
- 201871010106-丁宣元 《面向对象程序设计(java)》第二周学习总结
丁宣元 <面向对象程序设计(java)>第二周学习总结 正文开头 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在 ...
- Feign 报错:No fallback instance of type class xxx found for feign client xxx
通常需要确认配置内容: 开启 Hystrix:feign.hystrix.enabled=true Fallback类需要注解@Component 出处:https://www.jianshu.com ...
- ESA2GJK1DH1K升级篇: 远程升级准备工作: 安装Web服务器
前言 大家可以安装Apache,Tomcat,nginx 等Web服务器软件,这篇文章安装 OpenResty 作为Web服务器软件,该软件安装在云端电脑,如果想 安装到自己本地电脑实现该功能,可使用 ...