spring boot profiles使用
官方文档上解释,profiles是一种分离部分应用程序的配置方法;可以再开发过程中用profiles来控制开发、生产、测试等代码块的加载和使用。
使用spring.profiles.active=develop设置当前模式,然后在@Componment、@Configuration中使用@Profile("develop"),就可以启用和不启用当前组件加载!很像c#中的条件编译的用法!
#配置文件
spring.profiles.active=test,dev@Component
@Profile("test") //加载
public class SpringRunner implements ApplicationRunner {@Overridepublic void run(ApplicationArguments args) throws Exception {System.out.println("启动完成了 SpringRunner" );}
}@Component
@Profile("product") //不加载
public class CommandRunnerEvent implements CommandLineRunner {@Overridepublic void run(String... args) throws Exception {System.out.println("启动完成了 CommandRunnerEvent");}
}
spring boot profiles使用相关推荐
- 源码解读 Spring Boot Profiles
点击蓝色"程序猿DD"关注我 回复"资源"获取独家整理的学习资料! 前言 上文<一文掌握 Spring Boot Profiles> 是对 Spri ...
- 如何在Spring Boot应用程序中使用配置文件
你好朋友, 在本教程中,我们将学习如何在Spring Boot应用程序中使用配置文件. 我们将在本教程中讨论以下几点: 1.什么是Spring Boot Profile,为什么我们需要分析 2.如何使 ...
- spring boot + maven使用profiles进行环境隔离
Spring Profile Spring可使用Profile决定程序在不同环境下执行情况,包含配置.加载Bean.依赖等. Spring的Profile一般项目包含:dev(开发), test(单元 ...
- springboot中文文档_登顶 Github 的 Spring Boot 仓库!艿艿写的最肝系列
源码精品专栏 中文详细注释的开源项目 RPC 框架 Dubbo 源码解析 网络应用框架 Netty 源码解析 消息中间件 RocketMQ 源码解析 数据库中间件 Sharding-JDBC 和 My ...
- spring boot 实战 / 可执行war启动参数详解
概述 上一篇文章<spring boot 实战 / mvn spring-boot:run 参数详解>主要讲解了spring boot 项目基于maven插件启动过程中借助profil ...
- Spring Boot 2.0 常见问题总结(一)
SpringBoot2.x 依赖环境和版本新特性说明 依赖版本 jdk8 以上, Springboot2.x 用 JDK8 , 因为底层是 Spring framework5 . jar 包方式运行 ...
- 学习Spring Boot
Spring boot 是什么 ? 简单说, spring boot 是一个构建项目的工具, 一个脚手架. Spring boot 能干什么? spring boot 做非常少的配置就可以构建生产级别 ...
- (转) SpringBoot非官方教程 | 第二篇:Spring Boot配置文件详解
springboot采纳了建立生产就绪spring应用程序的观点. Spring Boot优先于配置的惯例,旨在让您尽快启动和运行.在一般情况下,我们不需要做太多的配置就能够让spring boot正 ...
- 我司Spring Boot 项目打包 + Shell 脚本部署详细总结,太有用了!
欢迎关注方志朋的博客,回复"666"获面试宝典 本篇和大家分享的是 Spring Boot 打包并结合 Shell 脚本命令部署,重点在分享一个shell 程序启动工具,希望能便利 ...
最新文章
- java 时间转换去杠
- python精要(66)—类(3)-文档字符串,注释文档
- 字节跳动自研万亿级图数据库 图计算实践 【太高级了,不是圈里的人,有简明见解的吗?】
- eclipse 配置java路径_如何在eclipse的配置文件里指定jdk路径
- ES6笔记 -- 字符串拓展
- .NET Framework各版本比较
- python发送excel文件_Python操作Excel, 开发和调用接口,发送邮件
- python显示乱码_python2显示乱码问题实战详解
- http 与https 区别浅析
- Gson转Map时,Int会变成double解决方法
- [转] 病毒、木马进程查询手册
- php购物车点击删除,求助 购物车 用session删除 列表的一条
- 用Elasticsearch做大规模数据的多字段、多类型索引检索
- 数独用计算机控制比数学家还厉害,用pl/sql解决芬兰数学家因卡拉设计的最难数独...
- Windows Xp sp2 升级为 sp3
- 基于Springboot的Java项目--新冠疫情统计系统
- gh ost mysql_MySQL DDL--gh-ost学习
- 创业实践案例课程答案
- 创业者必学的六种植物[转]
- ubuntu系统出错且无法恢复请联系管理员(A problem has occurred and the system can‘t recover,please contact the admini)