一、需要的注解
@ConfigurationProperties 配置属性文件,需要指定前缀 prefix
@Component是采用组件
二、POM依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
三、配置类
@Data
@Component
@ConfigurationProperties(prefix = "person")
public class JiuxianProperties {
private String name;
private int age;
private boolean boos;
@Data
static class Dog {
private String name;
private int age;
}
}
@SpringBootApplication
public class SpringbootYmlDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootYmlApplication.class, args);
}
}