com.jarvis.cache.autoconfigure.AutoloadCacheManageConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of autoload-cache-spring-boot-starter Show documentation
Show all versions of autoload-cache-spring-boot-starter Show documentation
autoload-cache spring boot starter.
The newest version!
package com.jarvis.cache.autoconfigure;
import com.jarvis.cache.ICacheManager;
import com.jarvis.cache.redis.AbstractRedisCacheManager;
import com.jarvis.cache.redis.JedisClusterCacheManager;
import com.jarvis.cache.redis.LettuceRedisClusterCacheManager;
import com.jarvis.cache.redis.SpringRedisCacheManager;
import com.jarvis.cache.script.AbstractScriptParser;
import com.jarvis.cache.script.OgnlParser;
import com.jarvis.cache.script.SpringELParser;
import com.jarvis.cache.serializer.HessianSerializer;
import com.jarvis.cache.serializer.ISerializer;
import com.jarvis.cache.serializer.JdkSerializer;
import com.jarvis.cache.serializer.KryoSerializer;
import io.lettuce.core.RedisClient;
import io.lettuce.core.cluster.RedisClusterClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.jedis.JedisClusterConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceClusterConnection;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisConnectionUtils;
import org.springframework.util.ClassUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
import java.lang.reflect.Field;
/**
* 对autoload-cache进行一些默认配置
* 如果需要自定义,需要自行覆盖即可
*
*
*/
@Slf4j
@Configuration
@ConditionalOnClass(name = "com.jarvis.cache.ICacheManager")
@EnableConfigurationProperties(AutoloadCacheProperties.class)
@AutoConfigureAfter(RedisAutoConfiguration.class)
@ConditionalOnProperty(value = "autoload.cache.enable", matchIfMissing = true)
public class AutoloadCacheManageConfiguration {
private static final boolean hessianPresent = ClassUtils.isPresent(
"com.caucho.hessian.io.AbstractSerializerFactory", AutoloadCacheManageConfiguration.class.getClassLoader());
private static final boolean kryoPresent = ClassUtils.isPresent(
"com.esotericsoftware.kryo.Kryo", AutoloadCacheManageConfiguration.class.getClassLoader());
/**
* 表达式解析器{@link AbstractScriptParser AbstractScriptParser} 注入规则:
* 如果导入了Ognl的jar包,优先 使用Ognl表达式:{@link OgnlParser
* OgnlParser},否则使用{@link SpringELParser SpringELParser}
*
* @return
*/
@Bean
@ConditionalOnMissingBean(AbstractScriptParser.class)
public AbstractScriptParser autoloadCacheScriptParser() {
return new SpringELParser();
}
/**
* * 序列化工具{@link ISerializer ISerializer} 注入规则:
* 如果导入了Hessian的jar包,优先使用Hessian:{@link HessianSerializer
* HessianSerializer},否则使用{@link JdkSerializer JdkSerializer}
*
* @return
*/
@Bean
@ConditionalOnMissingBean(ISerializer.class)
public ISerializer