redistemplate在set方法时,一直报java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String,请问是什么原因呢
private void doErrorCount(String action,
int maxErrorCount,
int duration,
String errorNotice) throws ApplicationException {
Integer count = (Integer) this.redisTemplate.opsForValue().get(action);
if (count == null) {
this.redisTemplate.opsForValue().set(action, 1, duration, TimeUnit.MINUTES);
} else {
CommonAssert.isTrue(count < maxErrorCount, errorNotice);
this.redisTemplate.opsForValue().increment(action, 1);
}
}
其中redisconfig配置为
StringRedisTemplate template = new StringRedisTemplate(factory);
// Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(
// Object.class);
// ObjectMapper om = new ObjectMapper();
// om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
// jackson2JsonRedisSerializer.setObjectMapper(om);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new JdkSerializationRedisSerializer());
template.setHashKeySerializer(new JdkSerializationRedisSerializer());
template.setHashValueSerializer(new JdkSerializationRedisSerializer());
template.afterPropertiesSet();