🎨 优化重构并统一公众号和小程序的spring boot starter部分配置类和属性

This commit is contained in:
Binary Wang
2020-08-30 10:50:25 +08:00
parent 64f7adcc29
commit 7cfabab628
10 changed files with 186 additions and 137 deletions

View File

@@ -9,6 +9,7 @@ import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import com.binarywang.spring.starter.wxjava.miniapp.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.miniapp.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
@@ -52,14 +53,19 @@ public class WxMaAutoConfiguration {
public WxMaService service(WxMaConfig wxMaConfig) {
HttpClientType httpClientType = wxMaProperties.getConfigStorage().getHttpClientType();
WxMaService wxMaService;
if (httpClientType == HttpClientType.OkHttp) {
wxMaService = new WxMaServiceOkHttpImpl();
} else if (httpClientType == HttpClientType.JoddHttp) {
wxMaService = new WxMaServiceJoddHttpImpl();
} else if (httpClientType == HttpClientType.HttpClient) {
wxMaService = new WxMaServiceHttpClientImpl();
} else {
wxMaService = new WxMaServiceImpl();
switch (httpClientType) {
case OkHttp:
wxMaService = new WxMaServiceOkHttpImpl();
break;
case JoddHttp:
wxMaService = new WxMaServiceJoddHttpImpl();
break;
case HttpClient:
wxMaService = new WxMaServiceHttpClientImpl();
break;
default:
wxMaService = new WxMaServiceImpl();
break;
}
wxMaService.setWxMaConfig(wxMaConfig);
return wxMaService;
@@ -102,7 +108,7 @@ public class WxMaAutoConfiguration {
}
private WxMaDefaultConfigImpl wxMaJedisConfigStorage() {
WxMaProperties.RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (StringUtils.isNotEmpty(redisProperties.getHost())) {
JedisPoolConfig config = new JedisPoolConfig();

View File

@@ -0,0 +1,43 @@
package com.binarywang.spring.starter.wxjava.miniapp.properties;
import lombok.Data;
/**
* redis 配置.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-08-30
*/
@Data
public class RedisProperties {
/**
* 主机地址.不填则从spring容器内获取JedisPool
*/
private String host;
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}

View File

@@ -88,37 +88,4 @@ public class WxMaProperties {
private String httpProxyPassword;
}
@Data
public static class RedisProperties {
/**
* 主机地址.不填则从spring容器内获取JedisPool
*/
private String host;
/**
* 端口号.
*/
private int port = 6379;
/**
* 密码.
*/
private String password;
/**
* 超时.
*/
private int timeout = 2000;
/**
* 数据库.
*/
private int database = 0;
private Integer maxActive;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer minIdle;
}
}