写入实体类
添加注解:
@Component
@ConfigurationProperties(prefix = “person”)
这个注解的依赖如下:
@ConfigurationProperties(prefix = “person”)
<!--读取配置文件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
写yml配置文件:
person:
name : houaid
age : 10
map : {a: 1,b: 2}
测试:
@SpringBootTest
class DemoApplicationTests {
@Autowired
Person person;
@Test
void contextLoads() {
System.out.println(person);
}
}
测试结果:读取成功