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 - ...
随机推荐
- 浅谈java枚举类
一.什么情况下使用枚举类? 有的时候一个类的对象是有限且固定的,这种情况下我们使用枚举类就比较方便? 二.为什么不用静态常量来替代枚举类呢? public static final int SEASO ...
- solr+ Eclipse 4.3+ tomcat 7.5 +winds7(一)
这种方法是我自己依据对tomcat运行项目流程和solr的运行流程来自己弄的,所以有点麻烦,请到原地址查看心血谢谢:http://blog.csdn.net/chunlei_zhang/article ...
- 怎样一步一步删除(linux & UNIX)环境下 oracle 11g 集群节点
Deleting a Cluster Node on Linux and UNIX Systems 1.确定要删除的节点,是否active,pinned $ olsnodes -s -t 假设 ...
- redis支持哪些数据类型
虽然redis的key和value之支持string和byte[],但是仍可以以string的形式保存其他格式,甚至是图片. 1)String: 用set(key,value),get(key) 2) ...
- C++中placement new操作符
placement new是重载operator new的一个标准.全局的版本,它不能被自定义的版本代替(不像普通的operator new和operator delete能够被替换成用户自定义的版本 ...
- IP地址的正则表达式
关键字:IP地址 正则表达式作者:txw1958出处:http://www.cnblogs.com/txw1958/archive/2011/10/13/ip_address_regular_expr ...
- maven私服nexus安装
maven私服nexus安装 1.nexus特性 1.1.nexus私服实际上是一个javaEE的web 系统 1.2.作用:用来管理一个公司所有的jar包,实现项目jar包的版本统一 1.3.jar ...
- 浅谈 Swift 中的 Optionals
input[type="date"].form-control,.input-group-sm>input[type="date"].input-grou ...
- XF内容视图和框架
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http:/ ...
- WPF 跨界面调用程序
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (System.Threading.ThreadStart)delegate() { sE ...