java需要POJO对象,以便使用SpringBoot自动连接下面的yml结构
应用程序。yml
countries:
country:
- name: kenya
insuffbal: test101
inactive: test101
- name: botswana
insuffbal: test102
inactive: test101
上面的yml结构需要使用Bean映射到java对象
国家。爪哇
@Component
@ConfigurationProperties(prefix = "countries.ke")
public class Countries {
//Need to map here - help me here
}
应用程序。爪哇
@SpringBootApplication
@EnableConfigurationProperties(Countries.class)
public class Application {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Application.class, args);
RepoProperties repoProperties = context.getBean(RepoProperties.class);
repoProperties.print();
}
}
# 1 楼答案
使用http://www.jsonschema2pojo.org/
只需将
yaml
文件粘贴到那里,然后选择源类型yaml
这是您需要定义的bean文件
现在只需将
Countries
自动连接到您想要使用的任何位置