一、yaml配置
1.application.yaml
person:
name: lds
age: 3
happy: true
brith: 2020/8/08
maps: {k1:v1,l2:v2}
lists:
code
music
dog:
name: wancai
age: 3
-
•
可以配置对象,数组等
-
•
注意分号后的空格
-
•
类与属性间存在包含关系
2.怎么用yaml向pojo传递
-
1.
创建pojo类 Person and Dog 类
public class Person {
private String name;
private Integer age;
private Boolean happy;
private Date brith;
private Map<String,Object> maps;
private List<Object> lists;
private Dog dog;
。。。。。。
2. 注入注解
@Component
@ConfigurationProperties(prefix = "person")
-
•
Component 表示这是个springboot组件
-
•
ConfigurationProperties配置文件
-
•
prefix 指向application.yaml
3. 测试Test
Person{name='lds', age=3, happy=true, brith=Sat Aug 08 00:00:00 GMT+08:00 2020, maps={k1v1=, l2v2=}, lists=[code music], dog=Dog{name='wancai', age=3}}
3.JSR303(数据校验)
@Validated // 数据校验
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
可以验证各种类型
3、application.properties
-
•
配置多环境
-
•
application-test.properties application-dev.properties
-
•
spring,profiles.active=(test)(dev)
-
•
application.yaml
server:
port: 8080 (默认)
spring:
profiles:
active: dev (8081)
---
server:
port: 8081
profiles: dev
---
server:
port: 8082
profiles: test
标签:typescript,application,配置,private,yaml,go,ruby From: https://www.cnblogs.com/Sammiedog/p/16810918.html