现在在的公司用spring.profiles.active=@profiles.active@ 当我看到这个的时候,一脸蒙蔽,这个@ 是啥意思。

这里其实是配合 maven profile进行选择不同配置文件进行开发

实战

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

好了,玩的开心

SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用的更多相关文章

  1. springboot(十九)使用actuator监控应用【转】【补】

    springboot(十九)使用actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的 ...

  2. springboot(十九)使用actuator监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  3. springboot(十九)-线程池的使用

    我们常用ThreadPoolExecutor提供的线程池服务,springboot框架提供了@Async注解,帮助我们更方便的将业务逻辑提交到线程池中异步执行. 话不多说,编码开始: 1.创建spri ...

  4. springboot(十九):使用Spring Boot Actuator监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  5. springboot(十九):SpringBoot+EHcache实现缓存

    https://blog.csdn.net/qq_28143647/article/details/79789368

  6. SpringBoot(十九)_404返回统一异常处理结果

    之前写过一篇统一异常处理的文章,今天测试了下如果访问一个不存在的接口,也想返回统一的错误信息,应该怎么做 1.修改application.properties文件 # 自定义404 #出现错误时, 直 ...

  7. SpringBoot利用spring.profiles.active=@spring.active@不同环境下灵活切换配置文件

    一.创建配置文件 配置文件结构:这里建三个配置文件,application.yml作为主配置文件配置所有共同的配置:-dev和-local分别配置两种环境下的不同配置内容,如数据库地址等. appli ...

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

  9. spring.profiles.active=@profiles.active@的含义

    spring.profiles.active=@profiles.active@ ,其实是配合 maven profile进行选择不同配置文件进行启动. 当执行 mvn clean package - ...

随机推荐

  1. SSH原理和使用

    ssh 是什么 在 linux 上工作,ssh 是必须要了解的技术方法.它可以建立起多台主机之间的安全的加密传输,以进行远程的访问.操控.传输数据. SSH 為 Secure Shell 的縮寫.為建 ...

  2. Bitmap,byte[],Drawable相互转化

    1.Drawable就是一个可画的对象.其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable).还有可能是一个图层(LayerDrawable),我们依据绘图 ...

  3. 浅谈java枚举类

    一.什么情况下使用枚举类? 有的时候一个类的对象是有限且固定的,这种情况下我们使用枚举类就比较方便? 二.为什么不用静态常量来替代枚举类呢? public static final int SEASO ...

  4. C++利用结构

    #include <iostream> using std::cout; using std::endl; //定义结构 struct Box{ double length; double ...

  5. 矿Spring入门Demo

    第一步:输入Spring jar 包裹 Spring核心包(4个)  日志包(2个)  jdbc模板支持(1个)  spring-jdbc-3.2.0.RELEASE.jar  模板相关事务处理包(1 ...

  6. Kafka Offset 1

    Kafka Offset Storage   1.概述 目前,Kafka 官网最新版[0.10.1.1],已默认将消费的 offset 迁入到了 Kafka 一个名为 __consumer_offse ...

  7. 使用CMD实现批量重命名[转]

    关键字:cmd DOS 批处理 批量 重命名 作者:lifesinger地址:http://www.cnblogs.com/txw1958/archive/2012/12/24/cmd-batch-r ...

  8. 潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据

    原文:潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据 目前自己对treeview的感慨很多 今天先讲 面对这种 表结构的数据 的其中 ...

  9. WPF RelativeSource的使用

    <Window x:Class="XamlTest.Window15"        xmlns="http://schemas.microsoft.com/win ...

  10. 用MVVM模式开发中遇到的零散问题总结(2)

    原文:用MVVM模式开发中遇到的零散问题总结(2) 本节目录: 1.解决动画属性被劫持问题 2.设置页面焦点默认所在对象 3.XAML模拟键盘按键 4.DataGrid数据源绑定到复杂格式(dynam ...