重构代码,调整配置的加载。
parent
1dbd00ccef
commit
960a4d4ef3
|
@ -1,6 +1,5 @@
|
|||
package xyz.zhouxy.plusone.mail;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -15,11 +14,10 @@ import org.springframework.mail.javamail.JavaMailSender;
|
|||
@Configuration
|
||||
@EnableConfigurationProperties(PlusoneMailProperties.class)
|
||||
@ConditionalOnClass(MailService.class)
|
||||
@EnableAutoConfiguration
|
||||
public class PlusoneMailAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public MailService mailService(JavaMailSender mailSender, PlusoneMailProperties mailProperties) {
|
||||
MailService mailService(JavaMailSender mailSender, PlusoneMailProperties mailProperties) {
|
||||
MailMessageFactory mailMessageFactory = new MailMessageFactory(mailProperties);
|
||||
return new SimpleMailService(mailSender, mailMessageFactory);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Objects;
|
|||
|
||||
import org.csource.common.MyException;
|
||||
import org.csource.fastdfs.ClientGlobal;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -20,7 +19,6 @@ import xyz.zhouxy.plusone.oss.FastDFSProperties.ConnectionPool;
|
|||
@Configuration
|
||||
@EnableConfigurationProperties(FastDFSProperties.class)
|
||||
@ConditionalOnClass(FastDFSUtil.class)
|
||||
@EnableAutoConfiguration
|
||||
public class FastDFSAutoConfig {
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -4,11 +4,6 @@ import java.util.List;
|
|||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigurationProperties("fastdfs")
|
||||
public class FastDFSProperties {
|
||||
private Integer connectTimeoutInSeconds;
|
||||
|
@ -21,12 +16,106 @@ public class FastDFSProperties {
|
|||
|
||||
private ConnectionPool connectionPool;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public Integer getConnectTimeoutInSeconds() {
|
||||
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 {
|
||||
private Boolean enabled;
|
||||
private Integer maxCountPerEntry;
|
||||
private Integer maxIdleTime;
|
||||
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>
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(value = {
|
||||
SmsProperties.class,
|
||||
SmsCredentialProperties.class,
|
||||
SmsClientProperties.class,
|
||||
SmsHttpProperties.class,
|
||||
SmsProxyProperties.class})
|
||||
@EnableConfigurationProperties(SmsProperties.class)
|
||||
@ConditionalOnClass(SmsService.class)
|
||||
public class PlusoneSmsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public SmsService smsService(SmsProperties smsProperties) {
|
||||
SmsService smsService(SmsProperties smsProperties) {
|
||||
return new TencentSmsServiceImpl(smsProperties);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,11 @@ import java.util.Map;
|
|||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* SMS 相关参数
|
||||
*
|
||||
* @author <a href="https://gitee.com/zhouxy108">ZhouXY</a>
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties("plusone.sms")
|
||||
public class SmsProperties {
|
||||
private String region;
|
||||
|
@ -19,33 +16,138 @@ public class SmsProperties {
|
|||
private SmsClientProperties client;
|
||||
private String appId;
|
||||
private Map<String, String> templates;
|
||||
}
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties("plusone.sms.credential")
|
||||
class SmsCredentialProperties {
|
||||
private String secretId;
|
||||
private String secretKey;
|
||||
}
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties("plusone.sms.client")
|
||||
class SmsClientProperties {
|
||||
private String signMethod;
|
||||
private SmsHttpProperties http;
|
||||
}
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties("plusone.sms.client.http")
|
||||
class SmsHttpProperties {
|
||||
private SmsProxyProperties proxy;
|
||||
private String reqMethod;
|
||||
private Integer connTimeout;
|
||||
}
|
||||
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 secretKey;
|
||||
|
||||
public String getSecretId() {
|
||||
return secretId;
|
||||
}
|
||||
|
||||
public void setSecretId(String secretId) {
|
||||
this.secretId = secretId;
|
||||
}
|
||||
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SmsClientProperties {
|
||||
private String signMethod;
|
||||
private SmsHttpProperties http;
|
||||
|
||||
public String getSignMethod() {
|
||||
return signMethod;
|
||||
}
|
||||
|
||||
public void setSignMethod(String signMethod) {
|
||||
this.signMethod = signMethod;
|
||||
}
|
||||
|
||||
public SmsHttpProperties getHttp() {
|
||||
return http;
|
||||
}
|
||||
|
||||
public void setHttp(SmsHttpProperties http) {
|
||||
this.http = http;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SmsHttpProperties {
|
||||
private SmsProxyProperties proxy;
|
||||
private String reqMethod;
|
||||
private Integer connTimeout;
|
||||
|
||||
public SmsProxyProperties getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public void setProxy(SmsProxyProperties proxy) {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties("plusone.sms.client.http.proxy")
|
||||
class SmsProxyProperties {
|
||||
private String host;
|
||||
private Integer port;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ import org.springframework.stereotype.Service;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import xyz.zhouxy.plusone.constant.ErrorCodeConsts;
|
||||
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 服务
|
||||
|
|
|
@ -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",
|
||||
"type": "java.lang.Boolean",
|
||||
"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
|
||||
app-id: 1111111111
|
||||
templates:
|
||||
code: 0000000
|
||||
'[code]': 0000000
|
||||
|
||||
# 邮件发送相关参数
|
||||
mail:
|
||||
|
|
|
@ -6,9 +6,9 @@ plusone:
|
|||
# 邮件发送相关参数
|
||||
mail:
|
||||
subject:
|
||||
code: Plusone
|
||||
'[code]': Plusone
|
||||
template:
|
||||
code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
||||
'[code]': 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
|
|
|
@ -6,9 +6,9 @@ plusone:
|
|||
# 邮件发送相关参数
|
||||
mail:
|
||||
subject:
|
||||
code: Plusone
|
||||
'[code]': Plusone
|
||||
template:
|
||||
code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
||||
'[code]': 【Plusone】验证码:%s,10分钟内有效,请勿泄露。
|
||||
# 日志配置
|
||||
logging:
|
||||
level:
|
||||
|
|
Loading…
Reference in New Issue