Skip to content

Commit cc6bc22

Browse files
committed
🎨 优化代码
1 parent daae431 commit cc6bc22

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
/**
3131
* 微信公众号存储策略自动配置.
3232
*
33-
* @author someone
33+
* @author Luo
3434
*/
3535
@Slf4j
3636
@Configuration
@@ -40,12 +40,6 @@ public class WxMpStorageAutoConfiguration {
4040

4141
private final WxMpProperties wxMpProperties;
4242

43-
@Value("${wx.mp.config-storage.redis.host:")
44-
private String redisHost;
45-
46-
@Value("${wx.mp.configStorage.redis.host:")
47-
private String redisHost2;
48-
4943
@Bean
5044
@ConditionalOnMissingBean(WxMpConfigStorage.class)
5145
public WxMpConfigStorage wxMpConfigStorage() {
@@ -81,14 +75,15 @@ private WxMpConfigStorage defaultConfigStorage() {
8175

8276
private WxMpConfigStorage jedisConfigStorage() {
8377
JedisPoolAbstract jedisPool;
84-
if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) {
78+
if (wxMpProperties.getConfigStorage() != null && wxMpProperties.getConfigStorage().getRedis() != null
79+
&& StringUtils.isNotEmpty(wxMpProperties.getConfigStorage().getRedis().getHost())) {
8580
jedisPool = getJedisPool();
8681
} else {
8782
jedisPool = applicationContext.getBean(JedisPool.class);
8883
}
8984
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
9085
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
91-
wxMpProperties.getConfigStorage().getKeyPrefix());
86+
wxMpProperties.getConfigStorage().getKeyPrefix());
9287
setWxMpInfo(wxMpRedisConfig);
9388
return wxMpRedisConfig;
9489
}
@@ -114,7 +109,7 @@ private WxMpConfigStorage redisTemplateConfigStorage() {
114109

115110
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
116111
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
117-
wxMpProperties.getConfigStorage().getKeyPrefix());
112+
wxMpProperties.getConfigStorage().getKeyPrefix());
118113

119114
setWxMpInfo(wxMpRedisConfig);
120115
return wxMpRedisConfig;
@@ -160,6 +155,6 @@ private JedisPoolAbstract getJedisPool() {
160155
}
161156

162157
return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
163-
redis.getDatabase());
158+
redis.getDatabase());
164159
}
165160
}

0 commit comments

Comments
 (0)