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 ...
随机推荐
- IOS—— strong weak retain assign 学习
转自:http://wenzongliang.iteye.com/blog/1746604 简单讲strong等同retain weak比assign多了一个功能,当对象消失后自动把指针变成nil,好 ...
- Cobaltstrike安装
1.下载JDK http://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase8-2177648.html#jd ...
- vue-router 在新窗口打开页面的功能
项目中,需要点击链接后再新窗口打开页面,大家知道vue是单页面应用开发框架,那么也不是不可以实现这个功能 很简单,详情看下面 1.<router-link>标签实现新窗口打开 <ro ...
- Centos7 安装腾达U12驱动无线网卡
解决过程: 办法一: CentOS7.3 默认的内核版本较低,为 3.10.0-514.el7.x86_64. 无论是使用腾达官方提供的驱动,还是github 上的驱动(链接 https://gith ...
- Linux的IP详解
俗话说:黑发不知勤学早,白首方悔读书迟. ...
- Fiddler抓包设置
介绍 Fiddler 在 PC 端和移动端,模拟器抓取数据包 Fiddler抓取PC端数据包: 这里 Fiddler 抓取网页客户端的数据包时,其原理就是在 客户端/浏览器 和 服务器端 之间,加上了 ...
- 【转】Pandas学习笔记(六)合并 merge
Pandas学习笔记系列: Pandas学习笔记(一)基本介绍 Pandas学习笔记(二)选择数据 Pandas学习笔记(三)修改&添加值 Pandas学习笔记(四)处理丢失值 Pandas学 ...
- docker学习11-上传本地镜像到镜像仓库
前言 在本地自己制作用过镜像后,上传到镜像仓库,这样方便在不同的机器上快速搭建同一套环境. 如果公开的话,别人也可以用你的镜像快速搭建环境,类似于 GitHub 本地代码上传到代码仓库,再从仓库拉取代 ...
- python 操作目录
每天写一点,总有一天我这条咸鱼能变得更咸 python 中对文件及目录的操作基本依赖与os,shutil模块,其中以os模块为主,最主要的几个方法实例如下: 1.判断文件/目录是否存在(os.path ...
- plv8 require 模块试用
plv8 是postgres 的一个比较强大的插件,社区有人基于babel,browserify 实现了一个方便的require 模块加载 实际上官方也有介绍过了类似的基于数据库存储js,然后通过ev ...