1 2 3 4 5
| public class Pet { private String type; private int age; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| @Component @ConfigurationProperties(prefix = "user")
public class User { private int id; private String username; private String password; private List hobby; private String\[\] song; private Map map; private Pet pet;
}
|
application.yeal 注意!冒号后有个空格!!! application.properties 比 application.yeal优先级高
1 2 3 4 5 6 7 8
| user: id: 2 username: linda password: 123 hobby: \[footboll,basketboll\] song: \[she,where\] map: {k1: v1,k2: v2} pet: {type: cat,age: 12}
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| 测试类
@RunWith(SpringRunner.class) @SpringBootTest public class Tests01 { @Autowired private User user; @Test public void test01(){ System.out.println(user); } }
|