Spring-Boot框架YAML进阶配置实现分文档和大文本效果------Spring-Boot框架
原创
©著作权归作者所有:来自51CTO博客作者旧约Alatus的原创作品,请联系作者获取转载授权,否则将追究法律责任
---
server:
port: 9999
spring:
servlet:
multipart:
max-file-size: 10MB
data:
redis:
host: 192.168.92.129
port: 6379
database: 0
password: abc123
lettuce:
pool:
max-active: 8
max-wait: -1ms
max-idle: 8
min-idle: 0
timeout: 5000
---
person:
name: 'Jack \n 123'
# 单引号不会识别转义字符
age: 20
birth-day: 2001/11/11 11:11:11
like: true
child:
name: "Rose \n 456"
# 双引号可以识别转义字符
age: 10
birth-day: 2011/11/11 11:11:11
# text: {"abc","def","ghj"}
test:
- abc
- def
# 大文本用-|开头会保留完整格式
- |
dogs:
- name: Tom
age: 3
- name: Jerry
age: 3
- >
aaa
bbb
ccc
# 大文本用->开头会将换行替换为空格
cats:
c1:
# name: 佩奇
# age: 8
{name : 佩奇,age: 8}
c2:
# name: 乔治
# age: 5
{name : 乔治,age: 5}
dogs:
- name: Tom
age: 3
- name: Jerry
age: 3
package com.example.boot3;
import com.example.boot3.bean.Person;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan("com.example")//改变包扫描路径
@SpringBootApplication(scanBasePackages = "com.example.boot3")//手动指定扫描包位置
public class Boot3Application
{
public static void main(String[] args) {
var ioc = SpringApplication.run(Boot3Application.class);
String[] names = ioc.getBeanDefinitionNames();
for (String name : names){
System.out.println(name);
}
Person person = ioc.getBean(Person.class);
System.out.println(person);
String s = person.getChild().getTest().get(2);
System.out.println(s);
String s1 = person.getChild().getTest().get(3);
System.out.println(s1);
}
}