|
@@ -23,71 +23,71 @@ import redis.clients.jedis.JedisPoolConfig;
|
|
|
@Configuration
|
|
|
@RequiredArgsConstructor
|
|
|
public class WxOpenStorageAutoConfiguration {
|
|
|
- private final WxOpenProperties properties;
|
|
|
+ private final WxOpenProperties properties;
|
|
|
|
|
|
- @Autowired(required = false)
|
|
|
- private JedisPool jedisPool;
|
|
|
+ @Autowired(required = false)
|
|
|
+ private JedisPool jedisPool;
|
|
|
|
|
|
- @Value("${wx.open.config-storage.redis.host:}")
|
|
|
- private String redisHost;
|
|
|
+ @Value("${wx.open.config-storage.redis.host:}")
|
|
|
+ private String redisHost;
|
|
|
|
|
|
- @Bean
|
|
|
- @ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
|
|
- public WxOpenConfigStorage wxOpenConfigStorage() {
|
|
|
- WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
|
|
|
- WxOpenProperties.StorageType type = storage.getType();
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnMissingBean(WxOpenConfigStorage.class)
|
|
|
+ public WxOpenConfigStorage wxOpenConfigStorage() {
|
|
|
+ WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
|
|
|
+ WxOpenProperties.StorageType type = storage.getType();
|
|
|
|
|
|
- if (type == WxOpenProperties.StorageType.redis) {
|
|
|
- return getWxOpenInRedisConfigStorage();
|
|
|
- }
|
|
|
- return getWxOpenInMemoryConfigStorage();
|
|
|
+ if (type == WxOpenProperties.StorageType.redis) {
|
|
|
+ return getWxOpenInRedisConfigStorage();
|
|
|
}
|
|
|
+ return getWxOpenInMemoryConfigStorage();
|
|
|
+ }
|
|
|
|
|
|
- private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() {
|
|
|
- WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
|
|
|
- setWxOpenInfo(config);
|
|
|
- return config;
|
|
|
- }
|
|
|
-
|
|
|
- private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {
|
|
|
- JedisPool poolToUse = jedisPool;
|
|
|
- if (jedisPool == null || StringUtils.isNotEmpty(redisHost)) {
|
|
|
- poolToUse = getJedisPool();
|
|
|
- }
|
|
|
- WxOpenInRedisConfigStorage config = new WxOpenInRedisConfigStorage(poolToUse);
|
|
|
- setWxOpenInfo(config);
|
|
|
- return config;
|
|
|
- }
|
|
|
+ private WxOpenInMemoryConfigStorage getWxOpenInMemoryConfigStorage() {
|
|
|
+ WxOpenInMemoryConfigStorage config = new WxOpenInMemoryConfigStorage();
|
|
|
+ setWxOpenInfo(config);
|
|
|
+ return config;
|
|
|
+ }
|
|
|
|
|
|
- private void setWxOpenInfo(WxOpenConfigStorage config) {
|
|
|
- config.setComponentAppId(properties.getAppId());
|
|
|
- config.setComponentAppSecret(properties.getSecret());
|
|
|
- config.setComponentToken(properties.getToken());
|
|
|
- config.setComponentAesKey(properties.getAesKey());
|
|
|
+ private WxOpenInRedisConfigStorage getWxOpenInRedisConfigStorage() {
|
|
|
+ JedisPool poolToUse = jedisPool;
|
|
|
+ if (jedisPool == null || StringUtils.isNotEmpty(redisHost)) {
|
|
|
+ poolToUse = getJedisPool();
|
|
|
}
|
|
|
+ WxOpenInRedisConfigStorage config = new WxOpenInRedisConfigStorage(poolToUse);
|
|
|
+ setWxOpenInfo(config);
|
|
|
+ return config;
|
|
|
+ }
|
|
|
|
|
|
- private JedisPool getJedisPool() {
|
|
|
- WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
|
|
|
- RedisProperties redis = storage.getRedis();
|
|
|
+ private void setWxOpenInfo(WxOpenConfigStorage config) {
|
|
|
+ config.setComponentAppId(properties.getAppId());
|
|
|
+ config.setComponentAppSecret(properties.getSecret());
|
|
|
+ config.setComponentToken(properties.getToken());
|
|
|
+ config.setComponentAesKey(properties.getAesKey());
|
|
|
+ }
|
|
|
|
|
|
- JedisPoolConfig config = new JedisPoolConfig();
|
|
|
- if (redis.getMaxActive() != null) {
|
|
|
- config.setMaxTotal(redis.getMaxActive());
|
|
|
- }
|
|
|
- if (redis.getMaxIdle() != null) {
|
|
|
- config.setMaxIdle(redis.getMaxIdle());
|
|
|
- }
|
|
|
- if (redis.getMaxWaitMillis() != null) {
|
|
|
- config.setMaxWaitMillis(redis.getMaxWaitMillis());
|
|
|
- }
|
|
|
- if (redis.getMinIdle() != null) {
|
|
|
- config.setMinIdle(redis.getMinIdle());
|
|
|
- }
|
|
|
- config.setTestOnBorrow(true);
|
|
|
- config.setTestWhileIdle(true);
|
|
|
+ private JedisPool getJedisPool() {
|
|
|
+ WxOpenProperties.ConfigStorage storage = properties.getConfigStorage();
|
|
|
+ RedisProperties redis = storage.getRedis();
|
|
|
|
|
|
- JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(),
|
|
|
- redis.getTimeout(), redis.getPassword(), redis.getDatabase());
|
|
|
- return pool;
|
|
|
+ JedisPoolConfig config = new JedisPoolConfig();
|
|
|
+ if (redis.getMaxActive() != null) {
|
|
|
+ config.setMaxTotal(redis.getMaxActive());
|
|
|
+ }
|
|
|
+ if (redis.getMaxIdle() != null) {
|
|
|
+ config.setMaxIdle(redis.getMaxIdle());
|
|
|
}
|
|
|
+ if (redis.getMaxWaitMillis() != null) {
|
|
|
+ config.setMaxWaitMillis(redis.getMaxWaitMillis());
|
|
|
+ }
|
|
|
+ if (redis.getMinIdle() != null) {
|
|
|
+ config.setMinIdle(redis.getMinIdle());
|
|
|
+ }
|
|
|
+ config.setTestOnBorrow(true);
|
|
|
+ config.setTestWhileIdle(true);
|
|
|
+
|
|
|
+ JedisPool pool = new JedisPool(config, redis.getHost(), redis.getPort(),
|
|
|
+ redis.getTimeout(), redis.getPassword(), redis.getDatabase());
|
|
|
+ return pool;
|
|
|
+ }
|
|
|
}
|