当前位置:网站首页>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
artifactIdConsistent 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 + SpaceAs 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
@Valuecoordination 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);
边栏推荐
- [Yugong series] go teaching course in July 2022 004 go code Notes
- mongodb/文档操作
- CVPR 2022 | 常见3D损坏和数据增强
- How to select the Block Editor? Impression notes verse, notation, flowus
- [quick start to digital IC Verification] 8. Typical circuits in digital ICs and their corresponding Verilog description methods
- leetcode刷题:二叉树18(最大二叉树)
- A way to calculate LNX
- Is it safe for Galaxy Securities to open an account online?
- Go language learning tutorial (XV)
- PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
猜你喜欢

IC科普文:ECO的那些事儿

B站UP搭建世界首个纯红石神经网络、基于深度学习动作识别的色情检测、陈天奇《机器学编译MLC》课程进展、AI前沿论文 | ShowMeAI资讯日报 #07.05

Go language | 02 for loop and the use of common functions

Zero cloud new UI design

Unity editor extended UI control

【数字IC验证快速入门】9、Verilog RTL设计必会的有限状态机(FSM)

leetcode刷题:二叉树15(找树左下角的值)

Leetcode skimming: binary tree 16 (path sum)

全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会

14、Transformer--VIT TNT BETR
随机推荐
全国爱眼教育大会,2022第四届北京国际青少年眼健康产业展会
ICTCLAS用的字Lucene4.9捆绑
Schema和Model
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
CVPR 2022 | 常见3D损坏和数据增强
【数字IC验证快速入门】2、通过一个SoC项目实例,了解SoC的架构,初探数字系统设计流程
1: Citation;
Model method
走入并行的世界
Schema and model
Enter the parallel world
How to retrieve the root password of MySQL if you forget it
Introduction to dead letter queue (two consumers, one producer)
sort和投影
Elk distributed log analysis system deployment (Huawei cloud)
Bzoj 3747 poi2015 kinoman segment tree
CCPC 2021威海 - G. Shinyruo and KFC(组合数,小技巧)
无卷积骨干网络:金字塔Transformer,提升目标检测/分割等任务精度(附源代码)...
[C language] merge sort
Leetcode(695)——岛屿的最大面积