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. Mybatis映射文件中的标签的使用

    <foreach> <!-- foreach --> <delete id="delMulti" parameterType="java.u ...

  2. 来自数组原型 Array.prototype 的遍历函数

    1. Array.prototype.forEach() forEach() 是一个专为遍历数组而生的方法,它没有返回值,也不会改变原数组,只是简单粗暴的将数组遍历一次  参数: callback() ...

  3. Ionic run android失败解决方法。

    今天在node.js窗口执行命令行ionic run android时就是报Error executing "adb device":error错,一开始以为是SDK不全,后来以为 ...

  4. Docker 0x08: Docker 命令

    目录 Docker 命令 run 与 start 区别 docker 进程相关命令 Restful API Docker 命令 docker命令容易混淆几个 run 与 start 区别 run: 会 ...

  5. Linux搭建邮件服务器Postfix+Dovecot+MySQL+PHP

    用于搭建的服务器信息 阿里云 Centos 6.5 32位 安装过程1.安装Postfix 版本(2:2.6.6-8.el6) yum -y install postfix 安装完成还需要替换系统自带 ...

  6. MySQL复制技术

    MySQL高可用方案 投票选举机制,较复杂 MySQL本身没有提供replication failover的解决方案,自动切换需要依赖MHA脚本 可以有多台从库,从库可以做报表和备份 MySQL复制技 ...

  7. 快速生成mysql上百万条测试数据

    方案:编写一个存储过程循环添加数据 1. 创建表index_test DROP TABLE IF EXISTS index_test; CREATE TABLE index_test( id ) PR ...

  8. [转]【jsp】

    建立时间:6.30 &7.12& 7.24& 7.27 7月心比较浮躁,几乎没怎么学习编程 一.JSP技术 1.jsp脚本和注释 jsp脚本: 1)<%java代码%&g ...

  9. 201671010449 杨天超 实验十四 团队项目评审&课程学习总结

    项目 内容 这个作业属于哪个课程 任课教师博客主页链接 这个作业的要求在哪里 作业链接地址 作业学习目标 1.掌握软件评审流程及内容 2.个人总结 实验一问题解答 实验一问题链接:https://ww ...

  10. 用bitSet做百万级ip去重

    如果直接将几百万数据仍到bitset,内存是否够用?实际测试,600万ip放到一个bitSet中,jvm内存会爆. 所以,就简单做了下分组,构建一个HashMap<String, BitSet& ...