搭建项目
参考 IDEA快速搭建spring-boot项目(Spring initializr)
pom.xml
创建项目后,还需在pom.xml
中的<dependencies>
标签添加该依赖。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
创建实体类
package com.demo.demo;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String name;
private int age;
@Override
public String toString() {
return "person{" +
"name='" + name + '\'' +
", age=" + age