Skip to content

Commit da512ff

Browse files
authored
🐛 #2015 【小程序】解决starter模块强制依赖jedis的问题
1 parent bac1b67 commit da512ff

File tree

1 file changed

+30
-26
lines changed
  • spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config

1 file changed

+30
-26
lines changed

spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public WxMaConfig wxMaConfig() {
7777
WxMaDefaultConfigImpl config;
7878
switch (wxMaProperties.getConfigStorage().getType()) {
7979
case Jedis:
80-
config = wxMaJedisConfigStorage();
80+
config = WxMaRedisBetterConfig.config(wxMaProperties, applicationContext);
8181
break;
8282
case RedisTemplate:
8383
config = wxMaRedisTemplateConfigStorage();
@@ -107,35 +107,39 @@ private WxMaDefaultConfigImpl wxMaDefaultConfigStorage() {
107107
return new WxMaDefaultConfigImpl();
108108
}
109109

110-
private WxMaDefaultConfigImpl wxMaJedisConfigStorage() {
111-
RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
112-
JedisPool jedisPool;
113-
if (StringUtils.isNotEmpty(redisProperties.getHost())) {
114-
JedisPoolConfig config = new JedisPoolConfig();
115-
if (redisProperties.getMaxActive() != null) {
116-
config.setMaxTotal(redisProperties.getMaxActive());
117-
}
118-
if (redisProperties.getMaxIdle() != null) {
119-
config.setMaxIdle(redisProperties.getMaxIdle());
120-
}
121-
if (redisProperties.getMaxWaitMillis() != null) {
122-
config.setMaxWaitMillis(redisProperties.getMaxWaitMillis());
123-
}
124-
if (redisProperties.getMinIdle() != null) {
125-
config.setMinIdle(redisProperties.getMinIdle());
126-
}
127-
config.setTestOnBorrow(true);
128-
config.setTestWhileIdle(true);
110+
private static class WxMaRedisBetterConfig {
129111

130-
jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
131-
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
132-
} else {
133-
jedisPool = applicationContext.getBean(JedisPool.class);
112+
private static WxMaDefaultConfigImpl config(WxMaProperties wxMaProperties, ApplicationContext context) {
113+
RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
114+
JedisPool jedisPool;
115+
if (StringUtils.isNotEmpty(redisProperties.getHost())) {
116+
JedisPoolConfig config = new JedisPoolConfig();
117+
if (redisProperties.getMaxActive() != null) {
118+
config.setMaxTotal(redisProperties.getMaxActive());
119+
}
120+
if (redisProperties.getMaxIdle() != null) {
121+
config.setMaxIdle(redisProperties.getMaxIdle());
122+
}
123+
if (redisProperties.getMaxWaitMillis() != null) {
124+
config.setMaxWaitMillis(redisProperties.getMaxWaitMillis());
125+
}
126+
if (redisProperties.getMinIdle() != null) {
127+
config.setMinIdle(redisProperties.getMinIdle());
128+
}
129+
config.setTestOnBorrow(true);
130+
config.setTestWhileIdle(true);
131+
132+
jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
133+
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
134+
} else {
135+
jedisPool = context.getBean(JedisPool.class);
136+
}
137+
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
138+
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
134139
}
135-
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
136-
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
137140
}
138141

142+
139143
private WxMaDefaultConfigImpl wxMaRedisTemplateConfigStorage() {
140144
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
141145
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);

0 commit comments

Comments
 (0)