重构代码,调整配置的加载。
parent
1dbd00ccef
commit
960a4d4ef3
|
@ -1,6 +1,5 @@
|
||||||
package xyz.zhouxy.plusone.mail;
|
package xyz.zhouxy.plusone.mail;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -15,11 +14,10 @@ import org.springframework.mail.javamail.JavaMailSender;
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(PlusoneMailProperties.class)
|
@EnableConfigurationProperties(PlusoneMailProperties.class)
|
||||||
@ConditionalOnClass(MailService.class)
|
@ConditionalOnClass(MailService.class)
|
||||||
@EnableAutoConfiguration
|
|
||||||
public class PlusoneMailAutoConfiguration {
|
public class PlusoneMailAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public MailService mailService(JavaMailSender mailSender, PlusoneMailProperties mailProperties) {
|
MailService mailService(JavaMailSender mailSender, PlusoneMailProperties mailProperties) {
|
||||||
MailMessageFactory mailMessageFactory = new MailMessageFactory(mailProperties);
|
MailMessageFactory mailMessageFactory = new MailMessageFactory(mailProperties);
|
||||||
return new SimpleMailService(mailSender, mailMessageFactory);
|
return new SimpleMailService(mailSender, mailMessageFactory);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Objects;
|
||||||
|
|
||||||
import org.csource.common.MyException;
|
import org.csource.common.MyException;
|
||||||
import org.csource.fastdfs.ClientGlobal;
|
import org.csource.fastdfs.ClientGlobal;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -20,7 +19,6 @@ import xyz.zhouxy.plusone.oss.FastDFSProperties.ConnectionPool;
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(FastDFSProperties.class)
|
@EnableConfigurationProperties(FastDFSProperties.class)
|
||||||
@ConditionalOnClass(FastDFSUtil.class)
|
@ConditionalOnClass(FastDFSUtil.class)
|
||||||
@EnableAutoConfiguration
|
|
||||||
public class FastDFSAutoConfig {
|
public class FastDFSAutoConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -4,11 +4,6 @@ import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ConfigurationProperties("fastdfs")
|
@ConfigurationProperties("fastdfs")
|
||||||
public class FastDFSProperties {
|
public class FastDFSProperties {
|
||||||
private Integer connectTimeoutInSeconds;
|
private Integer connectTimeoutInSeconds;
|
||||||
|
@ -21,12 +16,106 @@ public class FastDFSProperties {
|
||||||
|
|
||||||
private ConnectionPool connectionPool;
|
private ConnectionPool connectionPool;
|
||||||
|
|
||||||
@Getter
|
public Integer getConnectTimeoutInSeconds() {
|
||||||
@Setter
|
return connectTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectTimeoutInSeconds(Integer connectTimeoutInSeconds) {
|
||||||
|
this.connectTimeoutInSeconds = connectTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getNetworkTimeoutInSeconds() {
|
||||||
|
return networkTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNetworkTimeoutInSeconds(Integer networkTimeoutInSeconds) {
|
||||||
|
this.networkTimeoutInSeconds = networkTimeoutInSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCharset() {
|
||||||
|
return charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCharset(String charset) {
|
||||||
|
this.charset = charset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getHttpAntiStealToken() {
|
||||||
|
return httpAntiStealToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpAntiStealToken(Boolean httpAntiStealToken) {
|
||||||
|
this.httpAntiStealToken = httpAntiStealToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHttpSecretKey() {
|
||||||
|
return httpSecretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpSecretKey(String httpSecretKey) {
|
||||||
|
this.httpSecretKey = httpSecretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getHttpTrackerHttpPort() {
|
||||||
|
return httpTrackerHttpPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpTrackerHttpPort(Integer httpTrackerHttpPort) {
|
||||||
|
this.httpTrackerHttpPort = httpTrackerHttpPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTrackerServers() {
|
||||||
|
return trackerServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrackerServers(List<String> trackerServers) {
|
||||||
|
this.trackerServers = trackerServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConnectionPool getConnectionPool() {
|
||||||
|
return connectionPool;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnectionPool(ConnectionPool connectionPool) {
|
||||||
|
this.connectionPool = connectionPool;
|
||||||
|
}
|
||||||
|
|
||||||
public static class ConnectionPool {
|
public static class ConnectionPool {
|
||||||
private Boolean enabled;
|
private Boolean enabled;
|
||||||
private Integer maxCountPerEntry;
|
private Integer maxCountPerEntry;
|
||||||
private Integer maxIdleTime;
|
private Integer maxIdleTime;
|
||||||
private Integer maxWaitTimeInMs;
|
private Integer maxWaitTimeInMs;
|
||||||
|
|
||||||
|
public Boolean getEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(Boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxCountPerEntry() {
|
||||||
|
return maxCountPerEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxCountPerEntry(Integer maxCountPerEntry) {
|
||||||
|
this.maxCountPerEntry = maxCountPerEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxIdleTime() {
|
||||||
|
return maxIdleTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxIdleTime(Integer maxIdleTime) {
|
||||||
|
this.maxIdleTime = maxIdleTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getMaxWaitTimeInMs() {
|
||||||
|
return maxWaitTimeInMs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxWaitTimeInMs(Integer maxWaitTimeInMs) {
|
||||||
|
this.maxWaitTimeInMs = maxWaitTimeInMs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,17 +11,12 @@ import org.springframework.context.annotation.Configuration;
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(value = {
|
@EnableConfigurationProperties(SmsProperties.class)
|
||||||
SmsProperties.class,
|
|
||||||
SmsCredentialProperties.class,
|
|
||||||
SmsClientProperties.class,
|
|
||||||
SmsHttpProperties.class,
|
|
||||||
SmsProxyProperties.class})
|
|
||||||
@ConditionalOnClass(SmsService.class)
|
@ConditionalOnClass(SmsService.class)
|
||||||
public class PlusoneSmsAutoConfiguration {
|
public class PlusoneSmsAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SmsService smsService(SmsProperties smsProperties) {
|
SmsService smsService(SmsProperties smsProperties) {
|
||||||
return new TencentSmsServiceImpl(smsProperties);
|
return new TencentSmsServiceImpl(smsProperties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,11 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SMS 相关参数
|
* SMS 相关参数
|
||||||
*
|
*
|
||||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||||
*/
|
*/
|
||||||
@Data
|
|
||||||
@ConfigurationProperties("plusone.sms")
|
@ConfigurationProperties("plusone.sms")
|
||||||
public class SmsProperties {
|
public class SmsProperties {
|
||||||
private String region;
|
private String region;
|
||||||
|
@ -19,33 +16,138 @@ public class SmsProperties {
|
||||||
private SmsClientProperties client;
|
private SmsClientProperties client;
|
||||||
private String appId;
|
private String appId;
|
||||||
private Map<String, String> templates;
|
private Map<String, String> templates;
|
||||||
|
|
||||||
|
public String getRegion() {
|
||||||
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
public void setRegion(String region) {
|
||||||
@ConfigurationProperties("plusone.sms.credential")
|
this.region = region;
|
||||||
class SmsCredentialProperties {
|
}
|
||||||
|
|
||||||
|
public SmsCredentialProperties getCredential() {
|
||||||
|
return credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCredential(SmsCredentialProperties credential) {
|
||||||
|
this.credential = credential;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SmsClientProperties getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient(SmsClientProperties client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getTemplates() {
|
||||||
|
return templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemplates(Map<String, String> templates) {
|
||||||
|
this.templates = templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsCredentialProperties {
|
||||||
private String secretId;
|
private String secretId;
|
||||||
private String secretKey;
|
private String secretKey;
|
||||||
|
|
||||||
|
public String getSecretId() {
|
||||||
|
return secretId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
public void setSecretId(String secretId) {
|
||||||
@ConfigurationProperties("plusone.sms.client")
|
this.secretId = secretId;
|
||||||
class SmsClientProperties {
|
}
|
||||||
|
|
||||||
|
public String getSecretKey() {
|
||||||
|
return secretKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecretKey(String secretKey) {
|
||||||
|
this.secretKey = secretKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsClientProperties {
|
||||||
private String signMethod;
|
private String signMethod;
|
||||||
private SmsHttpProperties http;
|
private SmsHttpProperties http;
|
||||||
|
|
||||||
|
public String getSignMethod() {
|
||||||
|
return signMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
public void setSignMethod(String signMethod) {
|
||||||
@ConfigurationProperties("plusone.sms.client.http")
|
this.signMethod = signMethod;
|
||||||
class SmsHttpProperties {
|
}
|
||||||
|
|
||||||
|
public SmsHttpProperties getHttp() {
|
||||||
|
return http;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttp(SmsHttpProperties http) {
|
||||||
|
this.http = http;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsHttpProperties {
|
||||||
private SmsProxyProperties proxy;
|
private SmsProxyProperties proxy;
|
||||||
private String reqMethod;
|
private String reqMethod;
|
||||||
private Integer connTimeout;
|
private Integer connTimeout;
|
||||||
|
|
||||||
|
public SmsProxyProperties getProxy() {
|
||||||
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
public void setProxy(SmsProxyProperties proxy) {
|
||||||
@ConfigurationProperties("plusone.sms.client.http.proxy")
|
this.proxy = proxy;
|
||||||
class SmsProxyProperties {
|
}
|
||||||
|
|
||||||
|
public String getReqMethod() {
|
||||||
|
return reqMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReqMethod(String reqMethod) {
|
||||||
|
this.reqMethod = reqMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getConnTimeout() {
|
||||||
|
return connTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConnTimeout(Integer connTimeout) {
|
||||||
|
this.connTimeout = connTimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SmsProxyProperties {
|
||||||
private String host;
|
private String host;
|
||||||
private Integer port;
|
private Integer port;
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(Integer port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,9 @@ import org.springframework.stereotype.Service;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||||
import xyz.zhouxy.plusone.exception.PlusoneException;
|
import xyz.zhouxy.plusone.exception.PlusoneException;
|
||||||
|
import xyz.zhouxy.plusone.sms.SmsProperties.SmsCredentialProperties;
|
||||||
|
import xyz.zhouxy.plusone.sms.SmsProperties.SmsHttpProperties;
|
||||||
|
import xyz.zhouxy.plusone.sms.SmsProperties.SmsProxyProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用腾讯 SMS 服务
|
* 使用腾讯 SMS 服务
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
|
xyz.zhouxy.plusone.sms.PlusoneSmsAutoConfiguration,\
|
||||||
|
xyz.zhouxy.plusone.mail.PlusoneMailAutoConfiguration,\
|
||||||
|
xyz.zhouxy.plusone.oss.FastDFSAutoConfig
|
|
@ -28,30 +28,5 @@
|
||||||
"name": "plusone.exception.handle-all-exception",
|
"name": "plusone.exception.handle-all-exception",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
"description": "A description for 'plusone.exception.handle-all-exception'"
|
"description": "A description for 'plusone.exception.handle-all-exception'"
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fastdfs.http_anti_steal_token",
|
|
||||||
"type": "java.lang.String",
|
|
||||||
"description": "A description for 'fastdfs.http_anti_steal_token'"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fastdfs.http_secret_key",
|
|
||||||
"type": "java.lang.String",
|
|
||||||
"description": "A description for 'fastdfs.http_secret_key'"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fastdfs.http_tracker_http_port",
|
|
||||||
"type": "java.lang.String",
|
|
||||||
"description": "A description for 'fastdfs.http_tracker_http_port'"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fastdfs.network_timeout_in_seconds",
|
|
||||||
"type": "java.lang.String",
|
|
||||||
"description": "A description for 'fastdfs.network_timeout_in_seconds'"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "fastdfs.tracker_servers",
|
|
||||||
"type": "java.util.List",
|
|
||||||
"description": "A description for 'fastdfs.tracker_servers'"
|
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
|
|
|
@ -50,7 +50,7 @@ plusone:
|
||||||
conn-timeout: 60
|
conn-timeout: 60
|
||||||
app-id: 1111111111
|
app-id: 1111111111
|
||||||
templates:
|
templates:
|
||||||
code: 0000000
|
'[code]': 0000000
|
||||||
|
|
||||||
# 邮件发送相关参数
|
# 邮件发送相关参数
|
||||||
mail:
|
mail:
|
||||||
|
|
|
@ -6,9 +6,9 @@ plusone:
|
||||||
# 邮件发送相关参数
|
# 邮件发送相关参数
|
||||||
mail:
|
mail:
|
||||||
subject:
|
subject:
|
||||||
code: Plusone
|
'[code]': Plusone
|
||||||
template:
|
template:
|
||||||
code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
'[code]': 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
|
|
|
@ -6,9 +6,9 @@ plusone:
|
||||||
# 邮件发送相关参数
|
# 邮件发送相关参数
|
||||||
mail:
|
mail:
|
||||||
subject:
|
subject:
|
||||||
code: Plusone
|
'[code]': Plusone
|
||||||
template:
|
template:
|
||||||
code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
'[code]': 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
|
|
Loading…
Reference in New Issue