Skip to content

Commit da512ff

Browse files
authored
🐛 binarywang#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
WxMaDefaultConfigImplconfig;
7878
switch (wxMaProperties.getConfigStorage().getType()){
7979
caseJedis:
80-
config = wxMaJedisConfigStorage();
80+
config = WxMaRedisBetterConfig.config(wxMaProperties, applicationContext);
8181
break;
8282
caseRedisTemplate:
8383
config = wxMaRedisTemplateConfigStorage();
@@ -107,35 +107,39 @@ private WxMaDefaultConfigImpl wxMaDefaultConfigStorage(){
107107
returnnewWxMaDefaultConfigImpl();
108108
}
109109

110-
privateWxMaDefaultConfigImplwxMaJedisConfigStorage(){
111-
RedisPropertiesredisProperties = wxMaProperties.getConfigStorage().getRedis();
112-
JedisPooljedisPool;
113-
if (StringUtils.isNotEmpty(redisProperties.getHost())){
114-
JedisPoolConfigconfig = newJedisPoolConfig();
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+
privatestaticclassWxMaRedisBetterConfig{
129111

130-
jedisPool = newJedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
131-
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
132-
} else{
133-
jedisPool = applicationContext.getBean(JedisPool.class);
112+
privatestaticWxMaDefaultConfigImplconfig(WxMaPropertieswxMaProperties, ApplicationContextcontext){
113+
RedisPropertiesredisProperties = wxMaProperties.getConfigStorage().getRedis();
114+
JedisPooljedisPool;
115+
if (StringUtils.isNotEmpty(redisProperties.getHost())){
116+
JedisPoolConfigconfig = newJedisPoolConfig();
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 = newJedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
133+
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
134+
} else{
135+
jedisPool = context.getBean(JedisPool.class);
136+
}
137+
WxRedisOpsredisOps = newJedisWxRedisOps(jedisPool);
138+
returnnewWxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
134139
}
135-
WxRedisOpsredisOps = newJedisWxRedisOps(jedisPool);
136-
returnnewWxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
137140
}
138141

142+
139143
privateWxMaDefaultConfigImplwxMaRedisTemplateConfigStorage(){
140144
StringRedisTemplateredisTemplate = applicationContext.getBean(StringRedisTemplate.class);
141145
WxRedisOpsredisOps = newRedisTemplateWxRedisOps(redisTemplate);

0 commit comments

Comments
(0)