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. Vue+element 修改样式的scoped穿透方法

    我们在修改element的一些样式的时候,在加了scoped的时候会不起作用,下面是解决方案: 解决方法:起一个类名将页面包裹起来,后面加 /deep/ <style scoped> 1 ...

  3. mysql的常用查询创建命令

    查看所有数据库Show databases;创建数据库Create database 数据库名删除数据库Drop database 数据库名创建表CREATE TABLE t_bookType(   ...

  4. VMware vSphere API开发(一)---vSphere 体系核心概念

    1.VMware SDDC        VMware 软件定义数据中心(software defined dataCenter,SDDC),包括了从最底层的VMware vSphere.软件定义存储 ...

  5. 性能测试-MySQL性能查看(转)

    mysql查看数据库性能常用命令 mysql> show global status; 可以列出MySQL服务器运行各种状态值,另外,查询MySQL服务器配置信息语句: mysql> sh ...

  6. springboot日常问题处理手记

    springboot启动问题 1.@Autowired报错Could not autowire. No beans of xxx 解决:只需在DAO接口加上@Component 或者 @Reposit ...

  7. 监控进程cpu meminfo

    https://github.com/cdrandin/cpsc_351 https://github.com/cdrandin?after=Y3Vyc29yOnYyOpK5MjAxNC0wNy0xM ...

  8. centos7删除Apache组件

    非特殊需要不要删除centos7中Apache等组件!首先查看centos中Apache版本(前面我们说了centos7删除PHP,centos7删除MariaDB,可能很多朋友会有疑问为什么要把所有 ...

  9. js提取DOM属性和设置DOM属性值

    <style type="text/css"> #div1{width:100px;height:100px;} #div2{background} </styl ...

  10. Iptables不适用与socks协议吗?

    需求描述   现有一个台多公网IP服务器,用作于内网网关,通过NAT访问公网使用,要求不同的内网地址访问公网时使用不同的公网IP.可以简单理解为内网与公网IP进行一对一访问外网的映射. 服务器名称 I ...