当前位置:网站首页>【配置相关】
【配置相关】
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
五.自动配置原理
边栏推荐
- [jetson][转载]jetson上安装pycharm
- node(二)
- Sublime Text3 set different indents for different files
- 【AAAI】用于交通流预测的基于注意力的时空图卷积网络
- The purpose of DDD to divide domains, sub domains, core domains, and support domains
- [ts]Typescript学习记录坑点合集
- Shell notes (super complete)
- Div horizontal arrangement
- 详解:到底什么是GPS北斗授时服务器?
- Summary of window system operation skills
猜你喜欢

HarmonyOS 3.0 发布!

不堆概念、换个角度聊多线程并发编程

机器学习入门的百科全书-2018年“机器学习初学者”公众号文章汇总

Why does the system we developed have concurrent bugs? What is the root cause of concurrent bugs?

A little knowledge ~ miscellaneous notes on topics ~ a polymorphic problem

Does neural network sound tall? Take you to train a network from scratch (based on MNIST)
![[wechat applet] interface generates customized homepage QR code](/img/9b/cccdb8ff6db61518402a27b94d0196.png)
[wechat applet] interface generates customized homepage QR code

Sample is new and supported from API 8! Come and take it

Print out the "hourglass" and the remaining number according to the given number of characters and characters

Examples of specific usage of diagnostic instructions in s7-1200 and s7-1500 (led+devicestates+modulestates)
随机推荐
MySQL million level data migration practice notes
Talk about multithreaded concurrent programming from a different perspective without heap concept
机器学习之线性回归(最小二乘法手写+sklearn实现)
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
根据给定字符数和字符,打印输出“沙漏”和剩余数
网络图片转换本地图片 - 默认值或快捷键
Unity3d空包打apk报错汇总
TMS320C6000_ Tms320f28035 Chinese data manual
7.9-7.17 new features and grammar of learning plan ES6
Div horizontal layout aligned on both sides
“为机器立心”:朱松纯团队搭建人与机器人的价值双向对齐系统,解决人机协作领域的重大挑战
Summary of window system operation skills
[C language] minesweeping (recursive expansion + marking function)
Pytest+allure generate test report
JS 实现全屏效果
[wechat applet] interface generates customized homepage QR code
ORBSLAM2安装测试,及各种问题汇总
QoS服务质量五QoS边界行为之流量整形
A little knowledge ~ miscellaneous notes on topics ~ a polymorphic problem
Selenium series 5-xpath path expression