Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand SpringBoot profile

Shulou Source: shulou.com Published: 2022-06-03 10:10:45 11月15日 Update

This article will explain in detail how to understand the SpringBoot configuration file, the content of the article is of high quality, so Xiaobian shares it with you as a reference, I hope you have a certain understanding of relevant knowledge after reading this article.

1. File Type 1.1 properties

Same as previous properties.

1.2yaml Profile

YAML is a recursive acronym for YAML Ain't Markup Language (YAML is not a markup language). YAML actually meant "Yet Another Markup Language"(still a markup language) when it was developed.

Ideal for data-centric profiles.

basic syntax

key: value;kv with spaces

case sensitive

Use indentions to represent hierarchical relationships

Tabs are not allowed, only spaces are allowed.

The number of spaces indented doesn't matter, as long as elements at the same level are left justified.

#indicates comment

Strings do not need to be quoted. If you do,' ' escapes, and " " does not escape.

For example: "zhangsan\n small Pipi", single quotation marks will not wrap, double quotation marks will wrap.

data type

A single, indivisible value. date、boolean、string、number、null

k: v

Object: A collection of key-value pairs. map、hash、set、object

Inline writing: k: {k1: v1,k2: v2,k3: v3}

#or

k:

k1: v1

k2: v2

k3: v3

Array: A set of ordered values. array、list、queue

Inline writing: k: [v1,v2,v3]

#Or

k:

- v1

- v2

- v3

example

Two Entity Classes

@Data//lombok, Here has helped us to encapsulate the get, set method public class Person { private String userName; private Boolean boss; private Date birth; private Integer age; private Pet pet; private String[] interests; private List animal; private Map score; private Set salarys; private Map allPets;}@Datapublic class Pet { private String name; private Double weight;}

Yaml configuration:

# yaml represents the above object person: userName: zhangsan boss: false birth: 2019/12/12 20:12:33 age: 18 pet: name: tomcat weight: 23.4 interests: [basketball, swimming] animal: - jerry - mario score: english: first: 30 second: 40 third: 50 math: [131,140,148] chinese: {first: 128,second: 136} salarys: [3999,4999.98,5999.99] allPets: sick: - {name: tom} - {name: jerry,weight: 47} health: [{name: mario,weight: 47}]2. Configuration tips

Custom class and profile bindings are generally not prompted.

It can be seen that if you use spring's internal configuration in the yaml file, there will be a prompt, but if you use the class we defined, there will be no prompt. To improve development efficiency, just add dependencies to pom.xml:

org.springframework.boot spring-boot-configuration-processor true org.springframework.boot spring-boot-maven-plugin org.springframework.boot spring-boot-configuration-processor

Effect after adding dependency:

About how to understand the SpringBoot configuration file to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Tags: Configuration files quotes language hints content writing objects levels data articles more tags knowledge spaces articles types escape development good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Redmi macOS Shulou Technology Shulou Tech Info