one ,springboot Configuration file for

Usually :

application.properties

application.yaml

application.yml Three kinds

.properties Yes create springboot Automatically created by the project , Also before web Such technology or spring Default profile format for framework .

yaml and yml I don't know which one is used more at present , I usually use it yml, Because the priority is higher yaml high .

two , to configure

.properties The configuration form in is the key value pair form

for example :

1. Server port configuration :server.port=8080

2. modify springboot Enlightened logo:

Add on resources Add next banner.txt, It says what you want

I wrote the following :
____ _ _ | _ \ (_) | | | |_) | _ __ _ | | ___ __ _ ___ | _ < | | / _` || | /
_ \ / _` | / _ \ | |_) || || (_| || |____| (_) || (_| || (_) | |____/ |_| \__,
||______|\___/ \__, | \___/ __/ | __/ | |___/ |___/
After modification :

3. Modify log configuration :

You can set the log level of the specified directory , The default value is “info”
logging.level.root=info logging.level.com.xxx=warn/debug
three , Priority of the three

properties>yml>yaml

 

  When all three are present :

take properties, be left over yaml and yml Hour :

Thus, the priority order is properties>yml>yaml

four ,yml Data format inside ( Data should be separated by spaces and colons )

1. Data format characteristics :
Case sensitive ; Attribute hierarchy is described in multiple lines , End each line with a colon ;
Use indentation to represent hierarchical relationships , Align left side of the same level , Only spaces are allowed ( Not allowed Tab key , seemingly idea Will automatically identify );
Add a space before the attribute value ( Use colon between attribute name and attribute value + Space as separation ); # Indicates a comment .
2. Key value pair representation :
boolean: TRUE #TRUE,true,True Case is acceptable ,false Same thing float: 3.14 #6.8523015e+5 # Support scientific counting
int: 123 #0b1010_0111_0100_1010_1110 # Binary support , octal number system , hexadecimal null: ~ #~ express null string:
HelloWorld # Strings can be written directly string2: "Hello World" # Special characters can be wrapped in double quotation marks date: 2018-02-17
# Date must be used yyyy-MM-dd format datetime: 2018-02-17T15:02:31+08:00
# Use between time and date T connect , Last use + Represents time zone ( This is usually rare )
 3. Array representation :
likes: - eat - basketball - sleep liks2: [eat,basketball,sleep] users: - name:
zhangsan age: 23 - name: lisi age: 22 // A horizontal line is a set of data users3:
[{name:zhangsan,age:23},{name:lisi,age:24}] // You can also follow JSON Format to write
five , read yml data
use @Value Read single data , Attribute name reference method : ${ First level attribute name . Secondary attribute name ……}
1. Read single data

For example, I want to read the age of Zhang San :
@Value("${users[0].age}") private String age; // This is named age Just to look good , Independent of the variable name to be read
be careful : If a transfer character appears in the attribute value , Double quotation marks are required (\t and \n Is the escape character )
lesson: "Spring\tboot\nlesson"
2. use Environment Object encapsulates all configuration information

Or just print the age of Zhang San :
@Autowired private Environment environment;
System.out.println(env.getProperty("user[0].name"));
3. Encapsulate a set of data ( Custom object encapsulates specified data )

Compared with encapsulating all data , Encapsulate a set of data , I can take whatever I want
datasource: driver-class-name: com.mysql.cj.jdbc.Driver url:
jdbc:mysql://localhost:3306/ Database name ?serverTimezone=UTC username: root password: password
@Component @ConfigurationProperties(prefix = "datasource") public class
DataSource { private String driverClassName; private String url; private String
userName; private String password; } @RestController @RequestMapping("/run")
public class RunController { @Autowired private MyDataSource myDataSource; }
So I can get my own definition dataSource Configured data

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?