|
| 1 | +package org.baeldung.properties; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +import javax.validation.constraints.Max; |
| 7 | +import javax.validation.constraints.Min; |
| 8 | +import javax.validation.constraints.Pattern; |
| 9 | + |
| 10 | +import org.hibernate.validator.constraints.Length; |
| 11 | +import org.hibernate.validator.constraints.NotBlank; |
| 12 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 13 | +import org.springframework.context.annotation.Configuration; |
| 14 | +import org.springframework.context.annotation.PropertySource; |
| 15 | +import org.springframework.validation.annotation.Validated; |
| 16 | + |
| 17 | +@Configuration |
| 18 | +@PropertySource("classpath:configprops.properties") |
| 19 | +@ConfigurationProperties(prefix = "mail") |
| 20 | +@Validated |
| 21 | +public class ConfigProperties { |
| 22 | + |
| 23 | + @Validated |
| 24 | + public static class Credentials { |
| 25 | + |
| 26 | + @Length(max = 4, min = 1) |
| 27 | + private String authMethod; |
| 28 | + private String username; |
| 29 | + private String password; |
| 30 | + |
| 31 | + public String getAuthMethod() { |
| 32 | + return authMethod; |
| 33 | + } |
| 34 | + |
| 35 | + public void setAuthMethod(String authMethod) { |
| 36 | + this.authMethod = authMethod; |
| 37 | + } |
| 38 | + |
| 39 | + public String getUsername() { |
| 40 | + return username; |
| 41 | + } |
| 42 | + |
| 43 | + public void setUsername(String username) { |
| 44 | + this.username = username; |
| 45 | + } |
| 46 | + |
| 47 | + public String getPassword() { |
| 48 | + return password; |
| 49 | + } |
| 50 | + |
| 51 | + public void setPassword(String password) { |
| 52 | + this.password = password; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @NotBlank |
| 57 | + private String host; |
| 58 | + |
| 59 | + @Min(1025) |
| 60 | + @Max(65536) |
| 61 | + private int port; |
| 62 | + |
| 63 | + @Pattern(regexp = "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6}$") |
| 64 | + private String from; |
| 65 | + |
| 66 | + private Credentials credentials; |
| 67 | + private List<String> defaultRecipients; |
| 68 | + private Map<String, String> additionalHeaders; |
| 69 | + |
| 70 | + public String getHost() { |
| 71 | + return host; |
| 72 | + } |
| 73 | + |
| 74 | + public void setHost(String host) { |
| 75 | + this.host = host; |
| 76 | + } |
| 77 | + |
| 78 | + public int getPort() { |
| 79 | + return port; |
| 80 | + } |
| 81 | + |
| 82 | + public void setPort(int port) { |
| 83 | + this.port = port; |
| 84 | + } |
| 85 | + |
| 86 | + public String getFrom() { |
| 87 | + return from; |
| 88 | + } |
| 89 | + |
| 90 | + public void setFrom(String from) { |
| 91 | + this.from = from; |
| 92 | + } |
| 93 | + |
| 94 | + public Credentials getCredentials() { |
| 95 | + return credentials; |
| 96 | + } |
| 97 | + |
| 98 | + public void setCredentials(Credentials credentials) { |
| 99 | + this.credentials = credentials; |
| 100 | + } |
| 101 | + |
| 102 | + public List<String> getDefaultRecipients() { |
| 103 | + return defaultRecipients; |
| 104 | + } |
| 105 | + |
| 106 | + public void setDefaultRecipients(List<String> defaultRecipients) { |
| 107 | + this.defaultRecipients = defaultRecipients; |
| 108 | + } |
| 109 | + |
| 110 | + public Map<String, String> getAdditionalHeaders() { |
| 111 | + return additionalHeaders; |
| 112 | + } |
| 113 | + |
| 114 | + public void setAdditionalHeaders(Map<String, String> additionalHeaders) { |
| 115 | + this.additionalHeaders = additionalHeaders; |
| 116 | + } |
| 117 | +} |
0 commit comments