SpringBoot基础系列-使用Profiles
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9996884.html
SpringBoot基础系列-使用Profile
概述
Profile主要用于区分不同的环境。
使用方法
@Profile
在某个类、或者方法上添加@Profile注解,指定具体的profile环境标签,那么只又在该profile处于active的情况下该类,方法才会被加载、执行。
@Profile({"dev","test"})
public class Xxx{
@Profile({"dev"})
@Bean
public Xxx xxx(){
return new Xxx();
}
}
多环境配置
properties配置文件
使用properties配置文件实现多环境配置,只能通过添加多个application-{profile}.properties来实现。
比如:application-dev.properties,application-test.properties
YAML配置文件
使用YAML实现多环境配置要简单的多,只需要一个文件即可,application.yml
在文件中使用---来区分多个环境,每个环境都需要配置spring.profile属性,不配置的属于默认环境
server:
port: 8080
#属性映射测试
app:
name: springdemo
size: 100M
user: weiyihaoge
version: 0.0.1
---
spring:
profiles: dev
server:
port: 8081
---
spring:
profiles: test
server:
port: 8082
---
spring:
profiles: pro
server:
port: 8083
激活profiles
可以在命令行参数、系统参数、application.properties等处进行配置
命令行
--spring.profiles.active=dev
application.properties
spring.profiles.active=dev
添加profiles
我们可以在不修改已启动的profiles的基础上添加新的profiles
使用spring.profiles.include属性进行配置
还可以使用编程的方式实现,使用如下的方式添加:
SpringApplication.setAdditionalProfiles("development");
SpringBoot基础系列-使用Profiles的更多相关文章
- SpringBoot基础系列-使用日志
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9996897.html SpringBoot基础系列-使用日志 概述 SpringBoot ...
- SpringBoot基础系列-SpringBoot配置
原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...
- SpringBoot基础系列-SpringCache使用
原创文章,转载请标注出处:<SpringBoot基础系列-SpringCache使用> 一.概述 SpringCache本身是一个缓存体系的抽象实现,并没有具体的缓存能力,要使用Sprin ...
- 【SpringBoot 基础系列】实现一个自定义配置加载器(应用篇)
[SpringBoot 基础系列]实现一个自定义配置加载器(应用篇) Spring 中提供了@Value注解,用来绑定配置,可以实现从配置文件中,读取对应的配置并赋值给成员变量:某些时候,我们的配置可 ...
- 【SpringBoot基础系列】手把手实现国际化支持实例开发
[SpringBoot基础系列]手把手实现国际化支持实例开发 国际化的支持,对于app开发的小伙伴来说应该比价常见了:作为java后端的小伙伴,一般来讲接触国际化的机会不太多,毕竟业务开展到海外的企业 ...
- SpringBoot基础系列之自定义配置源使用姿势实例演示
[SpringBoot基础系列]自定义配置源的使用姿势介绍 前面一篇博文介绍了一个@Value的一些知识点,其中提了一个点,@Value对应的配置,除了是配置文件中之外,可以从其他的数据源中获取么,如 ...
- SpringBoot基础系列一
SpringBoot基础知识概览 特性 核心理念:约定优于配置 特点: 1. 开箱即用,根据项目依赖自动配置 2. 功能强大的服务体系,如嵌入式服务.安全 3. 绝无代码生成,不用写.xml配置,用注 ...
- 【SpringBoot基础系列-实战】如何指定 bean 最先加载(应用篇)
[基础系列-实战]如何指定 bean 最先加载(应用篇) 在日常的业务开发中,绝大多数我们都是不关注 bean 的加载顺序,然而如果在某些场景下,当我们希望某个 bean 优于其他的 bean 被实例 ...
- springBoot基础系列--properties配置
原创作品,可以转载,但是请标注出处地址:http://www.cnblogs.com/V1haoge/p/7183408.html SpringBoot中免除了大部分手动配置,但是对于一些特定的情况, ...
随机推荐
- MongoDB 用Robomong可视化工具操作的 一些简单语句
一.数据更新 db.getCollection('表名').update({ "字段":{$in:["值"]} }, //更新条件 {$set:{ " ...
- 【原创】XAF Winfrom 支持4K分辨率
Program.cs 添加以下代码 [STAThread] static void Main() { //支持4K显示 DevExpress.XtraEditors.WindowsFormsSetti ...
- mysql 水平分表
新建10张表,user_0,user_1,...user_9,方法不可串用,采用hash或取余法,获取要操作的表名,取值用对应存值的方法 1.hash取余法 public function part_ ...
- 对于bilibili主页head部分的代码的总结以及疑问。
1.lang=zh-Hans: lang代表languages的意思,VSCode创建出来的网页模板是lang=en,en代表english的意思,zh代表中文,单一的zh是废弃的语法,Hans代表中 ...
- 小程序block标签配合if和else 和 动态修改标题栏
<block wx:if="{{aaaa}}"> <view>aaaa为 true,显示</view> </block> <b ...
- koa2学习(二) 中间件router
中间件 koa-router 安装 npm install --save koa-router 使用 const Koa = require('koa'); const Router = requir ...
- Ubuntu 16.04下安装搜狗输入法
在确保更新了国内镜像源的前提下: 安装sogou输入法步骤 一.安装fcitx键盘输入法系统(系统已安装的可忽略此步骤) 1.添加以下源 sudo add-apt-repository ppa:fci ...
- 音视频编解码技术(二):AAC 音频编码技术
一.AAC编码概述 AAC是高级音频编码(Advanced Audio Coding)的缩写,出现于1997年,最初是基于MPEG-2的音频编码技术,目的是取代MP3格式.2000年,MPEG-4标准 ...
- [Swift]LeetCode230. 二叉搜索树中第K小的元素 | Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
- [Swift]LeetCode719. 找出第 k 小的距离对 | Find K-th Smallest Pair Distance
Given an integer array, return the k-th smallest distance among all the pairs. The distance of a pai ...