application.yml
person:
map1: {key1: value1,key2: value2}
map2:
1: val1
2: val2
list1: ["1","2","3"]
list2:
- 3
- 4
- 5
user: {id: 1,name: "张三"}
userList1: [{id: 1,name: "张三"},{id: 2,name: "李四"},{id: 3,name: "张三丰"}]
userList2:
- {id: 4,name: "张三92"}
- {id: 5,name: "李四73"}
- {id: 6,name: "张三丰"}
userMap1: {1: {id: 1,name: "张三"},2: {id: 2,name: "李四"},3: {id: 3,name: "张三丰"}}
userMap2:
1: {id: 1,name: "张三"}
2: {id: 2,name: "李四"}
3: {id: 3,name: "张三丰"}
输出结果
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.0)
2022-05-25 16:43:23,929[StartupInfoLogger.java:55][INFO]:[main]Starting DemoApplication using Java 17.0.1 on DESKTOP-MLPFQOC with PID 3560 (E:\springboot\22-boot\demo\target\classes started by Administrator in E:\springboot\22-boot\demo)
2022-05-25 16:43:23,931[SpringApplication.java:634][INFO]:[main]No active profile set, falling back to 1 default profile: "default"
2022-05-25 16:43:24,259[Config.java:38][INFO]:[main]map1={key1=value1, key2=value2}
2022-05-25 16:43:24,260[Config.java:39][INFO]:[main]map2={1=val1, 2=val2}
2022-05-25 16:43:24,261[Config.java:40][INFO]:[main]list1=[1, 2, 3]
2022-05-25 16:43:24,261[Config.java:41][INFO]:[main]list2=[3, 4, 5]
2022-05-25 16:43:24,261[Config.java:42][INFO]:[main]user=User(id=1, name=张三)
2022-05-25 16:43:24,261[Config.java:43][INFO]:[main]userList1=[User(id=1, name=张三), User(id=2, name=李四), User(id=3, name=张三丰)]
2022-05-25 16:43:24,261[Config.java:44][INFO]:[main]userList2=[User(id=4, name=张三92), User(id=5, name=李四73), User(id=6, name=张三丰)]
2022-05-25 16:43:24,261[Config.java:45][INFO]:[main]userMap1={1=User(id=1, name=张三), 2=User(id=2, name=李四), 3=User(id=3, name=张三丰)}
2022-05-25 16:43:24,261[Config.java:46][INFO]:[main]userMap2={1=User(id=1, name=张三), 2=User(id=2, name=李四), 3=User(id=3, name=张三丰)}
2022-05-25 16:43:24,300[StartupInfoLogger.java:61][INFO]:[main]Started DemoApplication in 0.694 seconds (JVM running for 1.121)
Config.java
package com.gzz.config;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import com.gzz.model.User;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@Data
@Slf4j
@Component
//@Configuration
@ConfigurationProperties(prefix = "person")
public class Config {
Map<String, String> map1;
Map<Integer, String> map2;
List<String> list1;
List<Integer> list2;
User user;
List<User> userList1;
List<User> userList2;
Map<Integer, User> userMap1;
Map<Integer, User> userMap2;
@PostConstruct
public void init() {
log.info("map1={}", map1);
log.info("map2={}", map2);
log.info("list1={}", list1);
log.info("list2={}", list2);
log.info("user={}", user);
log.info("userList1={}", userList1);
log.info("userList2={}", userList2);
log.info("userMap1={}", userMap1);
log.info("userMap2={}", userMap2);
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
网友评论