125 lines
2.9 KiB
Java
125 lines
2.9 KiB
Java
package com.baeldung.configurationproperties;
|
|
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.validation.constraints.Max;
|
|
import javax.validation.constraints.Min;
|
|
import javax.validation.constraints.NotBlank;
|
|
import javax.validation.constraints.Pattern;
|
|
|
|
import org.hibernate.validator.constraints.Length;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.PropertySource;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
@Configuration
|
|
@PropertySource("classpath:configprops.properties")
|
|
@ConfigurationProperties(prefix = "mail")
|
|
@Validated
|
|
public class ConfigProperties {
|
|
|
|
@Validated
|
|
public static class Credentials {
|
|
|
|
@Length(max = 4, min = 1)
|
|
private String authMethod;
|
|
private String username;
|
|
private String password;
|
|
|
|
public String getAuthMethod() {
|
|
return authMethod;
|
|
}
|
|
|
|
public void setAuthMethod(String authMethod) {
|
|
this.authMethod = authMethod;
|
|
}
|
|
|
|
public String getUsername() {
|
|
return username;
|
|
}
|
|
|
|
public void setUsername(String username) {
|
|
this.username = username;
|
|
}
|
|
|
|
public String getPassword() {
|
|
return password;
|
|
}
|
|
|
|
public void setPassword(String password) {
|
|
this.password = password;
|
|
}
|
|
}
|
|
|
|
@NotBlank
|
|
private String hostName;
|
|
|
|
@Min(1025)
|
|
@Max(65536)
|
|
private int port;
|
|
|
|
@Pattern(regexp = "^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,6}$")
|
|
private String from;
|
|
|
|
private Credentials credentials;
|
|
private List<String> defaultRecipients;
|
|
private Map<String, String> additionalHeaders;
|
|
|
|
public String getHostName() {
|
|
return hostName;
|
|
}
|
|
|
|
public void setHostName(String hostName) {
|
|
this.hostName = hostName;
|
|
}
|
|
|
|
public int getPort() {
|
|
return port;
|
|
}
|
|
|
|
public void setPort(int port) {
|
|
this.port = port;
|
|
}
|
|
|
|
public String getFrom() {
|
|
return from;
|
|
}
|
|
|
|
public void setFrom(String from) {
|
|
this.from = from;
|
|
}
|
|
|
|
public Credentials getCredentials() {
|
|
return credentials;
|
|
}
|
|
|
|
public void setCredentials(Credentials credentials) {
|
|
this.credentials = credentials;
|
|
}
|
|
|
|
public List<String> getDefaultRecipients() {
|
|
return defaultRecipients;
|
|
}
|
|
|
|
public void setDefaultRecipients(List<String> defaultRecipients) {
|
|
this.defaultRecipients = defaultRecipients;
|
|
}
|
|
|
|
public Map<String, String> getAdditionalHeaders() {
|
|
return additionalHeaders;
|
|
}
|
|
|
|
public void setAdditionalHeaders(Map<String, String> additionalHeaders) {
|
|
this.additionalHeaders = additionalHeaders;
|
|
}
|
|
|
|
@Bean
|
|
@ConfigurationProperties(prefix = "item")
|
|
public Item item(){
|
|
return new Item();
|
|
}
|
|
}
|