我要配置mybatis二级缓存为redis因为需要注入redis的ipportusername等等我需要构建JedisPoolConfig的bean,然后得到JedisConnectionFactory的bean而我定义的redis缓存如下finalclassMybatisCacheimplementsCache{privateStringidprivatefinalReadWriteLockreadWriteLock=newDummyReadWriteLock()privateRedisTemplateredisTemplate privateHashOperationshashOperations privatestaticJedisConnectionFactoryjedisConnectionFactorystaticsetJedisConnectionFactory(JedisConnectionFactoryfactory){jedisConnectionFactory=factory}MybatisCache(Stringid){if(id==null){thrownewIllegalArgumentException("CacheinstancesrequireanID")}else{this.id=idredisTemplate=newRedisTemplate()redisTemplate.setConnectionFactory(jedisConnectionFactory)redisTemplate.setKeySerializer(newStringRedisSerializer())redisTemplate.setValueSerializer(newGenericJackson2JsonRedisSerializer())redisTemplate.setHashKeySerializer(newGenericJackson2JsonRedisSerializer())redisTemplate.setHashValueSerializer(newGenericJackson2JsonRedisSerializer())redisTemplate.afterPropertiesSet()hashOperations=redisTemplate.opsForHash()}。。。}但是MybatisCache不是spring的bean,所以如果这个类被加载时JedisPoolConfig,JedisConnectionFactory等bean还没有初始化的话,就得到null,有没有什么办法让JedisPoolConfig,JedisConnectionFactory等bean能保证在MybatisCache被使用期前初始化?
陪伴而非守候
相关分类