当前位置:网站首页>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);
边栏推荐
- [quick start of Digital IC Verification] 3. Introduction to the whole process of Digital IC Design
- Go language | 01 wsl+vscode environment construction pit avoidance Guide
- 图嵌入Graph embedding学习笔记
- Wechat applet regular expression extraction link
- CTF逆向基础
- Database logic processing function
- 【c语言】归并排序
- - Oui. Net Distributed Transaction and Landing Solution
- [C language] merge sort
- 如何形成规范的接口文档
猜你喜欢
Unity编辑器扩展 UI控件篇
走入并行的世界
CVPR 2022 | 常见3D损坏和数据增强
[quick start of Digital IC Verification] 9. Finite state machine (FSM) necessary for Verilog RTL design
IC科普文:ECO的那些事儿
【数字IC验证快速入门】7、验证岗位中必备的数字电路基础知识(含常见面试题)
.Net分布式事務及落地解决方案
Scala basics [HelloWorld code parsing, variables and identifiers]
leetcode刷题:二叉树17(从中序与后序遍历序列构造二叉树)
Convolution free backbone network: Pyramid transformer to improve the accuracy of target detection / segmentation and other tasks (with source code)
随机推荐
死信队列入门(两个消费者,一个生产者)
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
14. Users, groups, and permissions (14)
1: Citation;
selenium 元素信息
Go language learning tutorial (16)
2020 CCPC 威海 - A. Golden Spirit(思维),D. ABC Conjecture(大数分解 / 思维)
BZOJ 3747 POI2015 Kinoman 段树
Bzoj 3747 poi2015 kinoman segment tree
sun. misc. Base64encoder error reporting solution [easy to understand]
Station B up builds the world's first pure red stone neural network, pornographic detection based on deep learning action recognition, Chen Tianqi's course progress of machine science compilation MLC,
物联网智能家居基本方法实现之经典
leetcode刷题:二叉树15(找树左下角的值)
July 4, 2022 - July 10, 2022 (UE4 video tutorial MySQL)
Schema和Model
Notes on key vocabulary in the English original of the biography of jobs (12) [chapter ten & eleven]
[quick start of Digital IC Verification] 1. Talk about Digital IC Verification, understand the contents of the column, and clarify the learning objectives
【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)
Solve the problem that the database configuration information under the ThinkPHP framework application directory is still connected by default after modification
Go language | 01 wsl+vscode environment construction pit avoidance Guide