From 960a4d4ef38bba12c531f7b20da9579c9891cb0f Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 10 Feb 2023 13:34:08 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=85=8D=E7=BD=AE=E7=9A=84=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mail/PlusoneMailAutoConfiguration.java | 4 +- .../zhouxy/plusone/oss/FastDFSAutoConfig.java | 2 - .../zhouxy/plusone/oss/FastDFSProperties.java | 103 +++++++++++- .../sms/PlusoneSmsAutoConfiguration.java | 9 +- .../xyz/zhouxy/plusone/sms/SmsProperties.java | 158 ++++++++++++++---- .../plusone/sms/TencentSmsServiceImpl.java | 3 + .../main/resources/META-INF/spring.factories | 4 + ...itional-spring-configuration-metadata.json | 25 --- .../main/resources/application-public.yaml | 2 +- .../src/main/resources/application.yaml | 4 +- .../src/test/resources/application.yaml | 4 +- 11 files changed, 241 insertions(+), 77 deletions(-) create mode 100644 plusone-basic/plusone-basic-infrastructure/src/main/resources/META-INF/spring.factories diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/mail/PlusoneMailAutoConfiguration.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/mail/PlusoneMailAutoConfiguration.java index 69db2b2..f99a131 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/mail/PlusoneMailAutoConfiguration.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/mail/PlusoneMailAutoConfiguration.java @@ -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); } diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSAutoConfig.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSAutoConfig.java index f4d7de2..8338ba2 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSAutoConfig.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSAutoConfig.java @@ -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 diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSProperties.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSProperties.java index 2d183ef..77aa621 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSProperties.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/oss/FastDFSProperties.java @@ -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 getTrackerServers() { + return trackerServers; + } + + public void setTrackerServers(List 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; + } } } diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/PlusoneSmsAutoConfiguration.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/PlusoneSmsAutoConfiguration.java index f712f41..594a2a2 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/PlusoneSmsAutoConfiguration.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/PlusoneSmsAutoConfiguration.java @@ -11,17 +11,12 @@ import org.springframework.context.annotation.Configuration; * @author ZhouXY */ @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); } } diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/SmsProperties.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/SmsProperties.java index 7107cd8..a6079c5 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/SmsProperties.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/SmsProperties.java @@ -4,14 +4,11 @@ import java.util.Map; import org.springframework.boot.context.properties.ConfigurationProperties; -import lombok.Data; - /** * SMS 相关参数 * * @author ZhouXY */ -@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 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 getTemplates() { + return templates; + } + + public void setTemplates(Map 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; } diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java index 7b7d319..da22bad 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java @@ -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 服务 diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/resources/META-INF/spring.factories b/plusone-basic/plusone-basic-infrastructure/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..509ef72 --- /dev/null +++ b/plusone-basic/plusone-basic-infrastructure/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + xyz.zhouxy.plusone.sms.PlusoneSmsAutoConfiguration,\ + xyz.zhouxy.plusone.mail.PlusoneMailAutoConfiguration,\ + xyz.zhouxy.plusone.oss.FastDFSAutoConfig diff --git a/plusone-start/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/plusone-start/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 1fc399c..ca1ef8f 100644 --- a/plusone-start/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/plusone-start/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -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'" } ]} diff --git a/plusone-start/src/main/resources/application-public.yaml b/plusone-start/src/main/resources/application-public.yaml index 2c4e7c0..3146c75 100644 --- a/plusone-start/src/main/resources/application-public.yaml +++ b/plusone-start/src/main/resources/application-public.yaml @@ -50,7 +50,7 @@ plusone: conn-timeout: 60 app-id: 1111111111 templates: - code: 0000000 + '[code]': 0000000 # 邮件发送相关参数 mail: diff --git a/plusone-start/src/main/resources/application.yaml b/plusone-start/src/main/resources/application.yaml index 378b5ed..5f762a4 100644 --- a/plusone-start/src/main/resources/application.yaml +++ b/plusone-start/src/main/resources/application.yaml @@ -6,9 +6,9 @@ plusone: # 邮件发送相关参数 mail: subject: - code: Plusone + '[code]': Plusone template: - code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。 + '[code]': 【Plusone】验证码:%s,10分钟内有效,请勿泄露。 # 日志配置 logging: level: diff --git a/plusone-start/src/test/resources/application.yaml b/plusone-start/src/test/resources/application.yaml index 96fd15b..661532b 100644 --- a/plusone-start/src/test/resources/application.yaml +++ b/plusone-start/src/test/resources/application.yaml @@ -6,9 +6,9 @@ plusone: # 邮件发送相关参数 mail: subject: - code: Plusone + '[code]': Plusone template: - code: 【Plusone】验证码:%s,10分钟内有效,请勿泄露。 + '[code]': 【Plusone】验证码:%s,10分钟内有效,请勿泄露。 # 日志配置 logging: level: