虽然冒红但是不影响运行
pom.xml文件:配置文件处理器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.1.9.RELEASE</version>
<optional>true</optional>
</dependency>
代码:
@Component
@EnableConfigurationProperties({Person.class})
@ConfigurationProperties(prefix = "person") //这个和配置属性匹配
public class Person {
private String username;
private int age;
private Date birthday;
private Map<String,Object>maps;
private List<Object>lists;
private Dog dog;
@Override
public String toString() {
return "Person{" +
"username='" + username + '\'' +
", age=" + age +
", birthday=" + birthday +
", maps=" + maps +
", lists=" + lists +
", dog=" + dog +
'}';
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public Map<String, Object> getMaps() {
return maps;
}
public void setMaps(Map<String, Object> maps) {
this.maps = maps;
}
public List<Object> getLists() {
return lists;
}
public void setLists(List<Object> lists) {
this.lists = lists;
}
public Dog getDog() {
return dog;
}
public void setDog(Dog dog) {
this.dog = dog;
}
}
冒红一定要解决加上@EnableConfigurationProperties({对应的类名.class})