1
0
mirror of synced 2025-12-18 22:08:01 +08:00

🐛 #2015 【小程序】解决starter模块强制依赖jedis的问题

This commit is contained in:
小锅盖
2021-02-26 22:13:41 +08:00
committed by GitHub
parent bac1b679b4
commit da512ff53d

View File

@@ -77,7 +77,7 @@ public class WxMaAutoConfiguration {
WxMaDefaultConfigImpl config; WxMaDefaultConfigImpl config;
switch (wxMaProperties.getConfigStorage().getType()) { switch (wxMaProperties.getConfigStorage().getType()) {
case Jedis: case Jedis:
config = wxMaJedisConfigStorage(); config = WxMaRedisBetterConfig.config(wxMaProperties, applicationContext);
break; break;
case RedisTemplate: case RedisTemplate:
config = wxMaRedisTemplateConfigStorage(); config = wxMaRedisTemplateConfigStorage();
@@ -107,7 +107,9 @@ public class WxMaAutoConfiguration {
return new WxMaDefaultConfigImpl(); return new WxMaDefaultConfigImpl();
} }
private WxMaDefaultConfigImpl wxMaJedisConfigStorage() { private static class WxMaRedisBetterConfig {
private static WxMaDefaultConfigImpl config(WxMaProperties wxMaProperties, ApplicationContext context) {
RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis(); RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
JedisPool jedisPool; JedisPool jedisPool;
if (StringUtils.isNotEmpty(redisProperties.getHost())) { if (StringUtils.isNotEmpty(redisProperties.getHost())) {
@@ -130,11 +132,13 @@ public class WxMaAutoConfiguration {
jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(), jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase()); redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
} else { } else {
jedisPool = applicationContext.getBean(JedisPool.class); jedisPool = context.getBean(JedisPool.class);
} }
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool); WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix()); return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
} }
}
private WxMaDefaultConfigImpl wxMaRedisTemplateConfigStorage() { private WxMaDefaultConfigImpl wxMaRedisTemplateConfigStorage() {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class); StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);