|
23 | 23 | @Configuration
|
24 | 24 | @RequiredArgsConstructor
|
25 | 25 | public class WxOpenStorageAutoConfiguration {
|
26 |
| - private final WxOpenProperties properties; |
| 26 | + private final WxOpenProperties properties; |
27 | 27 |
|
28 |
| - @Autowired(required = false) |
29 |
| - private JedisPool jedisPool; |
| 28 | + @Autowired(required = false) |
| 29 | + private JedisPool jedisPool; |
30 | 30 |
|
31 |
| - @Value("${wx.open.config-storage.redis.host:}") |
32 |
| - private String redisHost; |
| 31 | + @Value("${wx.open.config-storage.redis.host:}") |
| 32 | + private String redisHost; |
33 | 33 |
|
34 |
| - @Bean |
35 |
| - @ConditionalOnMissingBean(WxOpenConfigStorage.class) |
36 |
| - public WxOpenConfigStorage wxOpenConfigStorage() { |
37 |
| - WxOpenProperties.ConfigStorage storage = properties.getConfigStorage(); |
38 |
| - WxOpenProperties.StorageType type = storage.getType(); |
| 34 | + @Bean |
| 35 | + @ConditionalOnMissingBean(WxOpenConfigStorage.class) |
| 36 | + public WxOpenConfigStorage wxOpenConfigStorage() { |
| 37 | + WxOpenProperties.ConfigStorage storage = properties.getConfigStorage(); |
| 38 | + WxOpenProperties.StorageType type = storage.getType(); |
39 | 39 |
|
40 |
| - if (type == WxOpenProperties.StorageType.redis) { |
41 |
| - return getWxOpenInRedisConfigStorage(); |
42 |
| - } |
43 |
| - return getWxOpenInMemoryConfigStorage(); |
| 40 | + if (type == WxOpenProperties.StorageType.redis) { |
| 41 | + return getWxOpenInRedisConfigStorage(); |
44 | 42 | }
|
| 43 | + return getWxOpenInMemoryConfigStorage(); |
| 44 | + } |
45 | 45 |
|
46 |
| - private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() { |
47 |
| - WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage(); |
48 |
| - setWxOpenInfo(config); |
49 |
| - return config; |
50 |
| - } |
51 |
| - |
52 |
| - private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() { |
53 |
| - JedisPool poolToUse = jedisPool; |
54 |
| - if (jedisPool == null || StringUtils.isNotEmpty(redisHost)) { |
55 |
| - poolToUse = getJedisPool(); |
56 |
| - } |
57 |
| - WxOpenInRedisConfigStorage config = new WxOpenInRedisConfigStorage(poolToUse); |
58 |
| - setWxOpenInfo(config); |
59 |
| - return config; |
60 |
| - } |
| 46 | + private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() { |
| 47 | + WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage(); |
| 48 | + setWxOpenInfo(config); |
| 49 | + return config; |
| 50 | + } |
61 | 51 |
|
62 |
| - private void setWxOpenInfo(WxOpenConfigStorage config) { |
63 |
| - config.setComponentAppId(properties.getAppId()); |
64 |
| - config.setComponentAppSecret(properties.getSecret()); |
65 |
| - config.setComponentToken(properties.getToken()); |
66 |
| - config.setComponentAesKey(properties.getAesKey()); |
| 52 | + private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() { |
| 53 | + JedisPool poolToUse = jedisPool; |
| 54 | + if (jedisPool == null || StringUtils.isNotEmpty(redisHost)) { |
| 55 | + poolToUse = getJedisPool(); |
67 | 56 | }
|
| 57 | + WxOpenInRedisConfigStorage config = new WxOpenInRedisConfigStorage(poolToUse); |
| 58 | + setWxOpenInfo(config); |
| 59 | + return config; |
| 60 | + } |
68 | 61 |
|
69 |
| - private JedisPool getJedisPool() { |
70 |
| - WxOpenProperties.ConfigStorage storage = properties.getConfigStorage(); |
71 |
| - RedisProperties redis = storage.getRedis(); |
| 62 | + private void setWxOpenInfo(WxOpenConfigStorage config) { |
| 63 | + config.setComponentAppId(properties.getAppId()); |
| 64 | + config.setComponentAppSecret(properties.getSecret()); |
| 65 | + config.setComponentToken(properties.getToken()); |
| 66 | + config.setComponentAesKey(properties.getAesKey()); |
| 67 | + } |
72 | 68 |
|
73 |
| - JedisPoolConfig config = new JedisPoolConfig(); |
74 |
| - if (redis.getMaxActive() != null) { |
75 |
| - config.setMaxTotal(redis.getMaxActive()); |
76 |
| - } |
77 |
| - if (redis.getMaxIdle() != null) { |
78 |
| - config.setMaxIdle(redis.getMaxIdle()); |
79 |
| - } |
80 |
| - if (redis.getMaxWaitMillis() != null) { |
81 |
| - config.setMaxWaitMillis(redis.getMaxWaitMillis()); |
82 |
| - } |
83 |
| - if (redis.getMinIdle() != null) { |
84 |
| - config.setMinIdle(redis.getMinIdle()); |
85 |
| - } |
86 |
| - config.setTestOnBorrow(true); |
87 |
| - config.setTestWhileIdle(true); |
| 69 | + private JedisPool getJedisPool() { |
| 70 | + WxOpenProperties.ConfigStorage storage = properties.getConfigStorage(); |
| 71 | + RedisProperties redis = storage.getRedis(); |
88 | 72 |
|
89 |
| - JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(), |
90 |
| - redis.getTimeout(), redis.getPassword(), redis.getDatabase()); |
91 |
| - return pool; |
| 73 | + JedisPoolConfig config = new JedisPoolConfig(); |
| 74 | + if (redis.getMaxActive() != null) { |
| 75 | + config.setMaxTotal(redis.getMaxActive()); |
| 76 | + } |
| 77 | + if (redis.getMaxIdle() != null) { |
| 78 | + config.setMaxIdle(redis.getMaxIdle()); |
92 | 79 | }
|
| 80 | + if (redis.getMaxWaitMillis() != null) { |
| 81 | + config.setMaxWaitMillis(redis.getMaxWaitMillis()); |
| 82 | + } |
| 83 | + if (redis.getMinIdle() != null) { |
| 84 | + config.setMinIdle(redis.getMinIdle()); |
| 85 | + } |
| 86 | + config.setTestOnBorrow(true); |
| 87 | + config.setTestWhileIdle(true); |
| 88 | + |
| 89 | + JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(), |
| 90 | + redis.getTimeout(), redis.getPassword(), redis.getDatabase()); |
| 91 | + return pool; |
| 92 | + } |
93 | 93 | }
|
0 commit comments