当前位置:网站首页>【配置相关】
【配置相关】
2022-07-29 10:02:00 【赞赞儿_】
一[email protected]&@ImportResource&@Bean
@PropertySource:加载指定的配置文件;
@ImportResource:导入Spring的配置文件,让配置文件里面的内容生效;SpringBoot推荐给容器中添加组件的方式;推荐使用全注解的方式1、配置类@Configuration------>Spring配置文件 2、使用@Bean给容器中添加组件
二. Profile
1、多Profile文件
我们在主配置文件编写的时候,文件名可以是 application-{profile}.properties/yml
默认使用application.properties的配置;
2、yml支持多文档块方式
active: prod //激活指定profile
server:
port: 8081
spring:
profiles:
active: prod
---
server:
port: 8083
spring:
profiles: dev
---
server:
port: 8084
spring:
profiles: prod
3、激活指定profile
①、在配置文件中指定 spring.profiles.active=dev
②、命令行:
java -jar spring-boot-02-config-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev;
可以直接在测试的时候,配置传入命令行参数
③、虚拟机参数;
-Dspring.profiles.active=dev
三.配置文件加载位置
springboot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件
–file:./config/
–file:./
–classpath:/config/
–classpath:/
优先级由高到底,高优先级的配置会覆盖低优先级的配置;
SpringBoot会从这四个位置全部加载主配置文件;互补配置;
四.外部配置加载顺序
SpringBoot也可以从以下位置加载配置; 优先级从高到低;高优先级的配置覆盖低优先级的配置,所有的配置会形成互补配置
Spring Boot 支持多种外部配置方式
这些方式优先级如下:
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config
五.自动配置原理
边栏推荐
- Pytest+allure generate test report
- Skiasharp's WPF self drawn bouncing ball (case version)
- 函数——(C游记)
- TMS320C6000_ Tms320f28035 Chinese data manual
- Yin Yi: my learning and growth path
- “为机器立心”:朱松纯团队搭建人与机器人的价值双向对齐系统,解决人机协作领域的重大挑战
- [C language] minesweeping (recursive expansion + marking function)
- 这是一份不完整的数据竞赛年鉴!
- 【C语言】三子棋(智能下棋 + 阻拦玩家)
- How to customize the opportunity closing form in dynamics 365online
猜你喜欢

Yin Yi: my learning and growth path

程序员脱离单身的一些建议

【C语言】扫雷(递归展开 + 标记功能)

高效能7个习惯学习笔记

最新翻译的官方PyTorch简易入门教程(PyTorch1.0版本)

English grammar_ Indefinite pronouns - Common Phrases

This developer, who has been on the list for four consecutive weeks, has lived like a contemporary college student

不堆概念、换个角度聊多线程并发编程
![[ts]typescript learning record pit collection](/img/4c/14991ea612de8d5c94b758174a1c26.png)
[ts]typescript learning record pit collection
![[jetson][reprint]pycharm installed on Jetson](/img/65/ba7f1e7bd1b39cd67018e3f17d465b.png)
[jetson][reprint]pycharm installed on Jetson
随机推荐
[C language] minesweeping (recursive expansion + marking function)
The maximum length of VARCHAR2 type in Oracle is_ Oracle modify field length SQL
Correct posture and landing practice of R & D efficiency measurement (speech ppt sharing version)
一文读懂Plato Farm的ePLATO,以及其高溢价缘由
Sample is new and supported from API 8! Come and take it
Unity3d empty package APK error summary
汉源高科千兆2光6电导轨式网管型工业级以太网交换机支持X-Ring冗余环网一键环网交换机
Is it safe to open an account online now? Do you want to know that you must go to the business hall to open an account now?
机器学习之逻辑回归(Logistics Regression)
Summary of window system operation skills
Talk about multithreaded concurrent programming from a different perspective without heap concept
QoS服务质量五QoS边界行为之流量整形
[fortran]vscode configure FORTRAN to run Hello World
Source code analysis of senparc.weixin.sample.mp
How can Plato obtain premium income through elephant swap in a bear market?
通俗易懂讲解梯度下降法!
Excel tool for generating database table structure
CS research assurance experience in 2021 (VI): system filling + some thoughts
Why does the system we developed have concurrent bugs? What is the root cause of concurrent bugs?
What is Cartland number? What are the applications?