Reputation: 117
I'm using spring data redis and jedis with aspectJ for logging. But getting the below error. Please help in resolving this error. I have spent lot of time on this but couldn't resolve it.
I'm using spring data redis 1.4.1, jedis-2.6.1 with Redis-2.8
Error Details:-
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Illegal arguments to factory method [public org.springframework.data.redis.core.RedisTemplate com.test.RedisSentinelApplicationConfig.redisTemplate()]; args:
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:172)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
... 38 more
Below is the Java configuration file for the redis Sentinel configuration using spring data redis
@Configuration
public class RedisSentinelApplicationConfig {
private static final Logger logger = LoggerFactory.getLogger(RedisSentinelApplicationConfig.class);
@Autowired
private Environment env;
@Value("${redis.master}")
private String REDIS_MASTER;
public RedisSentinelConfiguration redisSentinelConfiguration() {
if(null != env){
logger.debug("env-->" + env.getProperty("redis.master"));
}else{
logger.debug("ENV object is null");
}
logger.debug("REDIS_MASTER-->" + REDIS_MASTER);
final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration()
.master(env.getProperty("redis.master"))
.sentinel(env.getProperty("redis.sentinel1.host"), Integer.valueOf(env.getProperty("redis.sentinel1.port")))
.sentinel(env.getProperty("redis.sentinel2.host"), Integer.valueOf(env.getProperty("redis.sentinel2.port")))
.sentinel(env.getProperty("redis.sentinel3.host"), Integer.valueOf(env.getProperty("redis.sentinel3.port")));
return SENTINEL_CONFIG;
}
@Bean
public RedisConnectionFactory jedisConnectionFactory() {
return new JedisConnectionFactory(sentinelConfig());
}
@Bean
public RedisSentinelConfiguration sentinelConfig() {
return redisSentinelConfiguration();
}
@Bean
public RedisTemplate<String, ?> redisTemplate() {
RedisTemplate<String, ?> template = new RedisTemplate();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(jackson2JsonRedisSerializer());
template.setHashValueSerializer(jackson2JsonRedisSerializer());
return template;
}
@SuppressWarnings("rawtypes")
@Bean(name="cacheService")
public CacheService CacheService() {
return new CacheServiceImpl();
}
@Bean
public Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer() {
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(
Object.class);
jackson2JsonRedisSerializer.setObjectMapper(objectMapper());
return jackson2JsonRedisSerializer;
}
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
return objectMapper;
}
}
Below is the Aspectj configuration for the logging. If I comment the @Component, apart from logging everything works perfectly fine but the same doesn't work if @Component exist. It looks like AspectJ is conflicting with spring data redis
@Component
@Aspect
public class PerfApplicationLogger {
private static final Logger log = LoggerFactory.getLogger(PerfApplicationLogger.class);
@Around("execution(* *(..))")
public Object logTimeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
Object retVal = joinPoint.proceed();
stopWatch.stop();
StringBuilder logMessage = new StringBuilder();
logMessage.append(joinPoint.getTarget().getClass().getName());
logMessage.append(".");
logMessage.append(joinPoint.getSignature().getName());
logMessage.append("(");
// append args
Object[] args = joinPoint.getArgs();
for (int i = 0; i < args.length; i++) {
logMessage.append(args[i]).append(",");
}
if (args.length > 0) {
logMessage.deleteCharAt(logMessage.length() - 1);
}
logMessage.append(")");
logMessage.append(" execution time: ");
logMessage.append(stopWatch.getTotalTimeMillis());
logMessage.append(" ms");
log.debug(logMessage.toString());
return retVal;
}
}
Upvotes: 1
Views: 3943
Reputation: 389
Please make sure spring-data-redis version is compatible with Jedis version.
As refer to the link (http://mvnrepository.com/artifact/org.springframework.data/spring-data-redis/1.4.1.RELEASE), spring-data-redis is compatible with Jedis 2.5.2. You should downgrade your jedis (2.6.1) version to 2.5.2.
Upvotes: 2