4、spring boot 配置文件之profile
Profile
1、多Profile文件
我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml
默认使用application.properties的配置;
2、yml支持多文档块方式
使用 --- 区分文档一、文档二、文档三
server:
port: 8081
spring:
profiles:
active: prod
‐‐‐
server:
port: 8083
spring:
profiles: dev
‐‐‐
server:
port: 8084
spring:
profiles: prod #指定属于哪个环境
3、激活指定profile
1、在配置文件中指定 spring.profiles.active=dev
2、命令行: java -jar spring-boot-02-config-0.0.1-SNAPSHOT.jar(项目的package文件) --spring.profiles.active=dev; 可以直接在测试的时候,配置传入命令行参数
3、虚拟机参数; -Dspring.profiles.active=dev
中的edit下的
指定文件运行位置
6、配置文件加载位置
springboot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件
–file:./config/
–file:./
–classpath:/config/
–classpath:/
优先级由高到底,高优先级的配置会覆盖低优先级的配置;
SpringBoot会从这四个位置全部加载主配置文件;互补配置;
我们还可以通过spring.config.location来改变默认的配置文件位置
项目打包好以后,我们可以使用命令行参数的形式,启动项目的时候来指定配置文件的新位置;指定配置文件和默 认加载的这些配置文件共同起作用形成互补配置;
java -jar spring-boot-02-config-02-0.0.1-SNAPSHOT.jar --spring.config.location=G:/application.properties
7、外部配置加载顺序
SpringBoot也可以从以下位置加载配置; 优先级从高到低;高优先级的配置覆盖低优先级的配置,所有的配置会 形成互补配置
1.命令行参数
所有的配置都可以在命令行上进行指定
java -jar spring-boot-02-config-02-0.0.1-SNAPSHOT.jar --server.port=8087 --server.context-path=/abc
多个配置用空格分开; --配置项=值
2.来自java:comp/env的JNDI属性
3.Java系统属性(System.getProperties())
4.操作系统环境变量
5.RandomValuePropertySource配置的random.*属性值
由jar包外向jar包内进行寻找,优先加载带profile
6.jar包外部的application-{profile}.properties或application.yml(带spring.profile)配置文件
7.jar包内部的application-{profile}.properties或application.yml(带spring.profile)配置文件
再来加载不带profile
8.jar包外部的application.properties或application.yml(不带spring.profile)配置文件
9.jar包内部的application.properties或application.yml(不带spring.profile)配置文件
10.@Configuration注解类上的@PropertySource
11.通过SpringApplication.setDefaultProperties指定的默认属性
所有支持的配置加载来源;
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/htmlsingle/#boot-features-external-config
4、spring boot 配置文件之profile的更多相关文章
- spring boot 配置文件application
场景:在项目部署的过程中,对于spring boot的配置文件一直不很了解,直到项目出现一个莫名其妙的问题——工程classes中的配置文件被覆盖,程序启动总是报错! 1 配置文件的优先级 appl ...
- 史上最全的Spring Boot配置文件详解
Spring Boot在工作中是用到的越来越广泛了,简单方便,有了它,效率提高不知道多少倍.Spring Boot配置文件对Spring Boot来说就是入门和基础,经常会用到,所以写下做个总结以便日 ...
- 黑马_13 Spring Boot:04.spring boot 配置文件
13 Spring Boot: 01.spring boot 介绍&&02.spring boot 入门 04.spring boot 配置文件 05.spring boot 整合其他 ...
- Spring Boot 配置文件详解
Spring Boot配置文件详解 Spring Boot提供了两种常用的配置文件,分别是properties文件和yml文件.他们的作用都是修改Spring Boot自动配置的默认值.相对于prop ...
- Springboot 系列(二)Spring Boot 配置文件
注意:本 Spring Boot 系列文章基于 Spring Boot 版本 v2.1.1.RELEASE 进行学习分析,版本不同可能会有细微差别. 前言 不管是通过官方提供的方式获取 Spring ...
- Spring Boot学习——Spring Boot配置文件application
Spring Boot配置文件有两种格式: application.properties 和 application.yml.两种配置文件只需要使用一个. 这两种配置文件的语法有些区别,如下 1. a ...
- Spring Boot配置文件大全
Spring Boot配置文件大全 ############################################################# # mvc ############## ...
- Spring Boot 配置文件和命令行配置
Spring Boot 属于约定大于配置,就是说 Spring Boot 推荐不做配置,很多都是默认配置,但如果想要配置系统,使得软件符合业务定义,Spring Boot 可以通过多种方式进行配置. ...
- Spring Boot 配置文件密码加密两种方案
Spring Boot 配置文件密码加密两种方案 jasypt 加解密 jasypt 是一个简单易用的加解密Java库,可以快速集成到 Spring 项目中.可以快速集成到 Spring Boot 项 ...
随机推荐
- Django Rest Framework进阶一
一.认证 认证请求头 #!/usr/bin/env python # -*- coding:utf-8 -*- from rest_framework.views import APIView fro ...
- input type="file"获取文件名方法
文件上传比较丑,样式调整时会有一个获取文件名,或者包含文件路径的文件名的方法 html代码 <div class="file-box"> <form id=&qu ...
- <Android 基础(十)> FloatingActionButton
介绍 Source Code中的介绍如下: Floating action buttons are used for a special type of promoted action. They a ...
- react-native 视频播放器(很不错哦)
第一步: npm i -S react-native-af-video-player(安装前:先安装: react-native-video.react-native-keep-awake.react ...
- 启动selenium server
java -jar selenium-server-standalone-2.37.0.jar
- Suggestion: use tools:overrideLibrary="android.support.v17.leanback" to force usage
Android Studio下修改方法: 在manifest中添加<uses-sdk tools:overrideLibrary="android.support.v17.leanba ...
- 笨办法学Python(三十七)
习题 37: 复习各种符号 现在该复习你学过的符号和 python 关键字了,而且你在本节还会学到一些新的东西.我在这里所作的是将所有的 Python 符号和关键字列出来,这些都是值得掌握的重点. 在 ...
- 笨办法学Python(零)
py走起!!! 习题0:准备工作 Windows平台 1. 用浏览器打开 http://learnpythonthehardway.org/exercise0.html 下载并安装 gedit 文本编 ...
- mysql [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GRO
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated c ...
- 命令搜索命令whereis与which
whereis 命令名 #搜索命令所在路径及帮助文档所在位置,只能搜索系统命令. 选项: -b: 只查找可执行文件 -m: 只查找帮助文件 whoami whatis ls #ls 是什么命令 whi ...