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配置

参考文章:http://www.likecs.com/show-62694.html

spring.profiles.active=@profiles.active@的含义的更多相关文章

  1. 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 ...

  2. SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用

    现在在的公司用spring.profiles.active=@profiles.active@ 当我看到这个的时候,一脸蒙蔽,这个@ 是啥意思. 这里其实是配合 maven profile进行选择不同 ...

  3. 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 ...

  4. spring boot配置项profiles active

    结论:通用项配置在applicaton.yml,区别环境配置在application-{profile}.yml中 一直不知道这个参数要不要配,配了有什么用,今天搭一个工程来检验 此项作用:用来区分不 ...

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

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

  6. Spring Boot features - Profiles

    https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html https://w ...

  7. Spring Boot常用的注解以及含义<持续更新>

    1.@RestController和@RequestMapping注解 @RestController 和 @RequestMapping 注解是Spring MVC注解(它们不是Spring Boo ...

  8. Spring学习之-各注解的含义总结

    注解配置 @ComponentScan("spittr.web"):/在加载Spring上下文时,会扫描spittr.web包查找组件 @ComponentScan注解扫描的组件有 ...

  9. Spring 各种注解(@)的含义与认识

    依赖注入,从字面上理解,即是:以注入的方式实现依赖: Spring 容器负责创建应用程序中的 bean,并通过 DI(依赖注入)来协调这些对象之间的关系.当描述 bean 如何进行装配(autowir ...

随机推荐

  1. 同一个POD中默认共享哪些名称空间

    如果通过POD的形式来启动多个容器那么它们的名称空间会是共享的么,所以我这里讨论是在默认情况下同一个POD的不同容器的哪些名称空间是打通的.这里先说一下结论,共享的是UTS.IPC.NET.USER. ...

  2. linux 忘记mysql用户root密码 解决方案

    1.vim /etc/my.cnf[mysqld]skip-grant-tables ##追加此行,跳过权限表, 2.重启mysqlsystemctl restart mysqld 3.mysql 登 ...

  3. 写给自己的 SOA 和 RPC 理解

    1.SOA SOA(Service-Oriented Architecture)面向服务架构,将应用程序不同功能单元(称为服务)进行拆分,并通过这些服务之间定义良好的接口和契约联系起来. SOA 不是 ...

  4. element表格的滚动条在合计上边

    默认滚动条是在下边的,不好看,这里改一下 修改样式.完美解决: .el-table { overflow-x: auto; } .el-table__header-wrapper, .el-table ...

  5. 第一篇 Scrum 冲刺博客

    一.各个成员在 Alpha 阶段认领的任务 姓名 Alpha 阶段认领的任务 林剑峰 用户信息页面:完成用户信息的上传 石竞贤 发布信息页面:完成用户图片上传云存储的功能,并且把发布信息上传到云数据库 ...

  6. HTTP是什么,不是什么?

    HTTP是什么? 不是什么? HTTP: 超文本传输协议,也就是HyperText Transfer Protocol.这是从字面上的理解,如果深一步的理解呢? HTTP又是什么呢? HTTP是什么 ...

  7. ASP.NET----内置对象----Resuest

    Request对象可以获取包含用户的计算机.页面及浏览器的请求等相关信息. Request对象的属性: ①Form----------返回有关表单变量的集合 ②QueryString--------- ...

  8. 微信小程序到底把什么定义为风险内容?

    目录 起因 经过和结果 附录: 起因 之前做一个群相册的小程序,因为涉及到图片和评论等内容的发布分享.因此,微信后台要求有一定的内容安全检测能力. 但是,我用别家的内容检测用的好好的,在国庆前被微信警 ...

  9. Linux下源码编译Mysql5.7

    1.安装依赖包 yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml libgc ...

  10. vmware虚拟机安装T6客户端

    1.虚拟机安装T6 经过测试,vmware 里系统装T6  网络适配器必须使用桥接,nat模式是无法连接数据库的