我有一个Spring Application.yml,其格式为:
emailservice:
url: www.example.com
emailtemplates:
- language: english
resetthepassword:
from: abc
subject: def
templatename: efg
authenticationStart:
from: 123
subject: 456
templatename: 789
- language: viatnamese
resetthepassword:
from: aaa
subject: bbb
templatename: ccc
resetthepassword:
from: ddd
subject: eee
templatename: fff
并且通过以下方式将其映射到java类:
@Configuration
@ConfigurationProperties("emailservice")
public class EmailServiceProperties {
private String url;
private List<EmailTemplate> emailTemplates;
// Getters, setters
}
public class EmailTemplate {
private String language;
private ResetThePassword resetthepassword;
private AuthenticationStart authenticationStart;
// getters and setters
}
public class ResetThePassword {
private String subject;
private String from;
private String templatename;
// getters and setters
}
public class AuthenticationStart {
private String subject;
private String from;
private String templatename;
// getters and setters
}
我想知道是否有更好的方法来映射application.yml属性?我可以在JSON变量中加载所有内容并使用@ConfigurationProperties吗?