SpringBoot多嵌套application.yml映射到多嵌套的ConfigurationProperties

时间:2019-05-28 19:47:27

标签: spring-boot spring-config

我有一个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吗?

0 个答案:

没有答案