diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java
index 0aad25f14..7c727c968 100644
--- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java
+++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java
@@ -9,8 +9,6 @@ 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.ConfigStorage;
-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;
@@ -89,7 +87,7 @@ public class WxMaAutoConfiguration {
config.setAesKey(StringUtils.trimToNull(this.wxMaProperties.getAesKey()));
config.setMsgDataFormat(StringUtils.trimToNull(this.wxMaProperties.getMsgDataFormat()));
- ConfigStorage configStorageProperties = wxMaProperties.getConfigStorage();
+ WxMaProperties.ConfigStorage configStorageProperties = wxMaProperties.getConfigStorage();
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
@@ -104,10 +102,27 @@ public class WxMaAutoConfiguration {
}
private WxMaDefaultConfigImpl wxMaJedisConfigStorage() {
- RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
+ WxMaProperties.RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
- if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
- jedisPool = getJedisPool();
+ if (StringUtils.isNotEmpty(redisProperties.getHost())) {
+ JedisPoolConfig config = new JedisPoolConfig();
+ if (redisProperties.getMaxActive() != null) {
+ config.setMaxTotal(redisProperties.getMaxActive());
+ }
+ if (redisProperties.getMaxIdle() != null) {
+ config.setMaxIdle(redisProperties.getMaxIdle());
+ }
+ if (redisProperties.getMaxWaitMillis() != null) {
+ config.setMaxWaitMillis(redisProperties.getMaxWaitMillis());
+ }
+ if (redisProperties.getMinIdle() != null) {
+ config.setMinIdle(redisProperties.getMinIdle());
+ }
+ config.setTestOnBorrow(true);
+ config.setTestWhileIdle(true);
+
+ jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
+ redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
@@ -120,28 +135,4 @@ public class WxMaAutoConfiguration {
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
}
-
- private JedisPool getJedisPool() {
- ConfigStorage storage = wxMaProperties.getConfigStorage();
- RedisProperties redis = storage.getRedis();
-
- JedisPoolConfig config = new JedisPoolConfig();
- if (redis.getMaxActive() != null) {
- config.setMaxTotal(redis.getMaxActive());
- }
- if (redis.getMaxIdle() != null) {
- config.setMaxIdle(redis.getMaxIdle());
- }
- if (redis.getMaxWaitMillis() != null) {
- config.setMaxWaitMillis(redis.getMaxWaitMillis());
- }
- if (redis.getMinIdle() != null) {
- config.setMinIdle(redis.getMinIdle());
- }
- config.setTestOnBorrow(true);
- config.setTestWhileIdle(true);
-
- return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
- redis.getDatabase());
- }
}
diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/ConfigStorage.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/ConfigStorage.java
deleted file mode 100644
index 921075d1d..000000000
--- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/ConfigStorage.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.binarywang.spring.starter.wxjava.miniapp.properties;
-
-import com.binarywang.spring.starter.wxjava.miniapp.enums.HttpClientType;
-import com.binarywang.spring.starter.wxjava.miniapp.enums.StorageType;
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-
-import java.io.Serializable;
-
-/**
- * 存储策略.
- *
- * @author Binary Wang
- * @date 2020-05-25
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Accessors(chain = true)
-public class ConfigStorage implements Serializable {
- private static final long serialVersionUID = 4815731027000065434L;
-
- /**
- * 存储类型.
- */
- private StorageType type = StorageType.Memory;
-
- /**
- * 指定key前缀.
- */
- private String keyPrefix = "wa";
-
- /**
- * redis连接配置.
- */
- private RedisProperties redis;
-
- /**
- * http客户端类型.
- */
- private HttpClientType httpClientType = HttpClientType.HttpClient;
-
- /**
- * http代理主机.
- */
- private String httpProxyHost;
-
- /**
- * http代理端口.
- */
- private Integer httpProxyPort;
-
- /**
- * http代理用户名.
- */
- private String httpProxyUsername;
-
- /**
- * http代理密码.
- */
- private String httpProxyPassword;
-
-}
diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/RedisProperties.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/RedisProperties.java
deleted file mode 100644
index 5e630c727..000000000
--- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/RedisProperties.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.binarywang.spring.starter.wxjava.miniapp.properties;
-
-import lombok.AllArgsConstructor;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-
-import java.io.Serializable;
-
-/**
- * redis配置.
- *
- * @author Binary Wang
- * @date 2020-05-25
- */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Accessors(chain = true)
-public class RedisProperties implements Serializable {
- private static final long serialVersionUID = -5924815351660074401L;
-
- /**
- * 主机地址.
- */
- 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;
-}
diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java
index 0bf267d6c..0139215ea 100644
--- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java
+++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java
@@ -1,5 +1,7 @@
package com.binarywang.spring.starter.wxjava.miniapp.properties;
+import com.binarywang.spring.starter.wxjava.miniapp.enums.HttpClientType;
+import com.binarywang.spring.starter.wxjava.miniapp.enums.StorageType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -40,6 +42,83 @@ public class WxMaProperties {
/**
* 存储策略
*/
- private ConfigStorage configStorage = new ConfigStorage();
+ private final ConfigStorage configStorage = new ConfigStorage();
+ @Data
+ public static class ConfigStorage {
+
+ /**
+ * 存储类型.
+ */
+ private StorageType type = StorageType.Memory;
+
+ /**
+ * 指定key前缀.
+ */
+ private String keyPrefix = "wa";
+
+ /**
+ * redis连接配置.
+ */
+ private final RedisProperties redis = new RedisProperties();
+
+ /**
+ * http客户端类型.
+ */
+ private HttpClientType httpClientType = HttpClientType.HttpClient;
+
+ /**
+ * http代理主机.
+ */
+ private String httpProxyHost;
+
+ /**
+ * http代理端口.
+ */
+ private Integer httpProxyPort;
+
+ /**
+ * http代理用户名.
+ */
+ private String httpProxyUsername;
+
+ /**
+ * http代理密码.
+ */
+ 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;
+ }
}