SpringBoot(十九)_spring.profiles.active=@profiles.active@ 的使用
现在在的公司用
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@ 的使用的更多相关文章
- springboot(十九)使用actuator监控应用【转】【补】
springboot(十九)使用actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的 ...
- springboot(十九)使用actuator监控应用
微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...
- springboot(十九)-线程池的使用
我们常用ThreadPoolExecutor提供的线程池服务,springboot框架提供了@Async注解,帮助我们更方便的将业务逻辑提交到线程池中异步执行. 话不多说,编码开始: 1.创建spri ...
- springboot(十九):使用Spring Boot Actuator监控应用
微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...
- springboot(十九):SpringBoot+EHcache实现缓存
https://blog.csdn.net/qq_28143647/article/details/79789368
- SpringBoot(十九)_404返回统一异常处理结果
之前写过一篇统一异常处理的文章,今天测试了下如果访问一个不存在的接口,也想返回统一的错误信息,应该怎么做 1.修改application.properties文件 # 自定义404 #出现错误时, 直 ...
- SpringBoot利用spring.profiles.active=@spring.active@不同环境下灵活切换配置文件
一.创建配置文件 配置文件结构:这里建三个配置文件,application.yml作为主配置文件配置所有共同的配置:-dev和-local分别配置两种环境下的不同配置内容,如数据库地址等. appli ...
- 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 ...
- spring.profiles.active=@profiles.active@的含义
spring.profiles.active=@profiles.active@ ,其实是配合 maven profile进行选择不同配置文件进行启动. 当执行 mvn clean package - ...
随机推荐
- Web 程序的建立
1 导读 web 基础研发体系指的是, web 研发中一线工程师所直接操作的技术.工具,以及所属组织架构的总和.在过去提升企业研发效能的讨论中,围绕的主题基本都是——”通过云计算.云存储等方式将底层核 ...
- 机器学习编程接口(api)设计(oop 设计)
fit: 对于 kmeans 来说,fit 的过程,就是训练,自然所需的参数,主要是数据集和聚类中心数, 1. classification(分类) def train(train_images, t ...
- 设计模式(四)The Factory Pattern 出厂模式
一.简单工厂 定义:定义一个创建对象的接口,可是由其子类决定要实例化的对象是哪一个,工厂方法让类的实例化推迟到子类. 通俗的来讲就是由工厂方法确定一个框架.详细的实现由其子类来完毕. 与简单工厂相比, ...
- 数学思想方法-python计算战(8)-机器视觉-二值化
二值化 hreshold Applies a fixed-level threshold to each array element. C++: double threshold(InputArray ...
- Flask框架2
Flask框架的学习与实战(二):实战小项目 昨天写了一篇flask开发环境搭建,今天继续,进行一个实战小项目-blog系统. blog系统很简单,只有一个页面,然后麻雀虽小五脏俱全.这里目的不是 ...
- GDI+与WPF中的颜色简析
原文:GDI+与WPF中的颜色简析 --------------------------------------------------------------------------------引用 ...
- Visual C# 2010 实现资源管理器
演练:使用设计器创建带有 ListView 和 TreeView 控件的资源管理器样式的界面 Visual Studio 2010 其他版本 此主题尚未评级 - 评价此主题 Vis ...
- python发送电子邮件
或者收发邮件都得小心翼翼的,怕一不小心被有心人瞧见,又得被说说. 为了能发邮件而不被发现,嘿嘿.我就用python写了个邮件发送程序,用控制台控制,不了解的人一定以为哥还在编程工作呢.哈哈. 以下简介 ...
- 文章之间的基本总结Activity生命周期
子曰:溫故而知新,能够為師矣.<論語> 学习技术也一样,对于技术文档或者经典的技术书籍来说,指望看一遍就全然掌握,那基本不大可能,所以我们须要常常回过头再细致研读几遍,以领悟到作者的思想精 ...
- js如何通过变量调用函数,函数名在变量里面
js如何通过变量调用函数,函数名在变量里面. 有时候函数名是动态定义的,这时候我们就需要用到这个方法了. //赋值函数名称 var a = "b"; //定义函数 function ...