Spring Boot @ConfigurationProperties 注解的实现属性绑定
1、定义配置文件
jie:
name: jie
sex: 男
enable: true
roles:
- USER
- ADMIN
2、定义实体类
@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
@ConfigurationProperties("jie")
public class MyBean {
private String name;
private String sex;
private Boolean enable;
private List<String> roles;
}
3、编写测试用例
@SpringBootTest
class DemoApplicationTests {
@Autowired
private MyBean myBean;
@Test
void contextLoads() {
System.out.println(myBean);
}
}
4、运行结果