Use mail to do the example. The configuration is placed in the Mail.properties file. The property must be named for the specification to bind successfully.
Spring Boot uses some loose rules to bind attributes to the @ConfigurationProperties
bean and supports a hierarchical structure (hierarchical structure).
To start creating a @ConfigurationProperties
bean:
@ConfigurationProperties(locations = "classpath:mail.properties", ignoreUnknownFields = false, prefix = "mail")public class MailProperties { public static class Smtp { private boolean auth; private boolean starttlsEnable; // ... getters and setters } @NotBlank private String host; private int port; private String from; private String username; private String password; @NotNull private Smtp smtp; // ... getters and setters}
... Created from the following properties (mail.properties):
mail.host=localhostmail.port=25mail.smtp.auth=falsemail.smtp.starttls-enable=false[email protected]mail.username=mail.password=
Crocodile_b
Links: Http://www.jianshu.com/p/df57fefe0ab7
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Original: Http://www.jianshu.com/p/df57fefe0ab7
Using @ConfigurationProperties annotations in spring boot