当前位置:网站首页>Fundamentals - configuration file analysis
Fundamentals - configuration file analysis
2022-07-05 20:19:00 【Printf ('xiaobai ');】
To configure
Copy module
- Delete the file of the previous project ,
Leave only pom.xml and src file
- modify pom In the document
artifactId
Consistent with the new project- If not modified name Label words , Try to put name Labels and description All labels are deleted
- Just keep the backup
Attribute configuration (application.properties)
- Each configuration corresponds to technology , If you don't quote a certain technology , There will be no code prompt in the configuration file
- Official configuration file
# Server port configuration
server.port=80
# modify banner
#spring.main.banner-mode=console
# modify banner chart
#spring.banner.image.location=ysg.jpg
# journal
logging.level.root=info
There are three types of configuration files
When three coexist properties > yml > yaml
- The same attribute will take priority , Different configurations will keep the configuration
- properties
yml
yaml
- properties
Add configuration file
- Configuration file automatic code prompt
yml The configuration file
- advantage
- Easy to read
Easy to interact with scripts
Data core , Data over format
- Easy to read
- Rule of grammar
- Case sensitive
Attribute hierarchies are described in multiple lines , End each line with a colon
Use indentation to indicate hierarchy , Align left side of the same level , Only Spaces are allowed
Add a space before the attribute value ( Use between attribute name and attribute valueThe colon + Space
As a division ) - # Notation
- Case sensitive
- yml Various data formats in the file
# Server port configuration
server:
port: 81
country: china
party: true
birthday: 1949-10-01
null: ~
# An object
user:
name: ssc
age: 23
# Multi level objects
a:
b:
c:
d: 5
# Array
likes:
- game
- music
- sleep
-
likes1: [game,music,sleep]
# An array of objects
users:
-
name: zhangsan
age: 18
-
name: wangwu
age: 23
users1:
- name: zhangsan
age: 18
- name: wangwu
age: 23
users2: [{
name:zhangsan,age:18},{
name:lisi,age:17}]
Read yml File data
- annotation
@Value
coordination SpEL Read single data , Multiple data are read hierarchically
// read yml Single data of data in
@Value("${country}")
private String country1;
// object
@Value("${user.name}")
private String name1;
// Array
@Value("${likes[1]}")
private String likes1;
// Array objects
@Value("${users[0].age}")
private String age1;
// Port number
@Value("${server.port}")
private String port;
Variable references & Escape character
# Variable references
baseDir: c:\windows
tempDir: ${
baseDir}\temp
# Escape character
tempDir1: "${baseDir}\temp \t1 \t2 \t3 \t4"
// Variable references
@Value("${tempDir}")
private String tempDir;
// Escape character
@Value("${tempDir1}")
private String tempDir1;
Read all yml attribute
- Use Environment Object encapsulates all information
- Use @Autowired Automatically assemble data to Environment In the object
- env.getProperty(“server.port”) Read different properties
// Read all yml attribute , Automatic assembly
@Autowired
private Environment env;
System.out.println(env.getProperty("server.port"));
System.out.println(env);
Read yml Reference data type ( Commonly used
)
- yml Define an object data type
# Reference data types that need to be read
datasource:
driver: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/mybatis
username: root
password: 123456
- Specify the corresponding class
// spring Managed Bean
@Component
// Specify the loaded yml A property of
@ConfigurationProperties(prefix = "datasource")
@Data
public class MyDataSource {
private String driver;
private String url;
private String username;
private String password;
}
- Output
System.out.println(myDataSource);
边栏推荐
- sun. misc. Base64encoder error reporting solution [easy to understand]
- .Net分布式事務及落地解决方案
- 信息学奥赛一本通 1338:【例3-3】医院设置 | 洛谷 P1364 医院设置
- . Net distributed transaction and landing solution
- 点云文件的.dat文件读取保存
- Introduction to dead letter queue (two consumers, one producer)
- Is it safe for Galaxy Securities to open an account online?
- When JS method passes long type ID value, precision loss will occur
- Leetcode brush questions: binary tree 18 (largest binary tree)
- USACO3.4 “破锣摇滚”乐队 Raucous Rockers - DP
猜你喜欢
Introduction to dead letter queue (two consumers, one producer)
Autumn byte interviewer asked you any questions? In fact, you have stepped on thunder
基础篇——配置文件解析
[Yugong series] go teaching course in July 2022 004 go code Notes
解决Thinkphp框架应用目录下数据库配置信息修改后依然按默认方式连接
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
图嵌入Graph embedding学习笔记
Leetcode brush question: binary tree 14 (sum of left leaves)
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
Securerandom things | true and false random numbers
随机推荐
Leetcode brush questions: binary tree 11 (balanced binary tree)
物联网智能家居基本方法实现之经典
A solution to PHP's inability to convert strings into JSON
[quick start of Digital IC Verification] 7. Basic knowledge of digital circuits necessary for verification positions (including common interview questions)
About the priority of Bram IP reset
leetcode刷题:二叉树14(左叶子之和)
Is it safe for CICC fortune to open an account online?
Zero cloud new UI design
Mysql频繁操作出现锁表问题
19 mongoose modularization
Leetcode skimming: binary tree 17 (construct binary tree from middle order and post order traversal sequence)
BZOJ 3747 POI2015 Kinoman 段树
kubernetes资源对象介绍及常用命令(五)-(ConfigMap&Secret)
CCPC 2021威海 - G. Shinyruo and KFC(组合数,小技巧)
DP:树DP
点云文件的.dat文件读取保存
[quick start of Digital IC Verification] 6. Quick start of questasim (taking the design and verification of full adder as an example)
【c语言】快速排序的三种实现以及优化细节
Elk distributed log analysis system deployment (Huawei cloud)
ffplay文档[通俗易懂]