Using @ConfigurationProperties annotations in spring boot

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.