Merge branch 'hotfix_redis_util' into pre
This commit is contained in:
commit
87b0262c95
@ -17,6 +17,7 @@
|
||||
package cn.axzo.pokonyan.config.jsonserializer;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
@ -48,7 +49,7 @@ public class JacksonConfiguration {
|
||||
builder.simpleDateFormat(DatePattern.NORM_DATETIME_PATTERN);
|
||||
// builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer());
|
||||
// builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer());
|
||||
builder.modules(new JackSonTimeModule());
|
||||
builder.modules(new JackSonTimeModule(), new JavaTimeModule());
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
package cn.axzo.pokonyan.config.redis;
|
||||
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
@ -19,6 +22,8 @@ import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
import org.springframework.data.redis.core.types.Expiration;
|
||||
import org.springframework.data.redis.serializer.SerializationException;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -41,6 +46,24 @@ public class RedisUtil implements InitializingBean {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
RedisUtil.redisTemplate = SpringUtil.getBean(StringRedisTemplate.class);
|
||||
redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer(){
|
||||
@Override
|
||||
public byte[] serialize(Object object) throws SerializationException {
|
||||
return super.serialize(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object deserialize(byte[] bytes) throws SerializationException {
|
||||
try {
|
||||
return new StringRedisSerializer().deserialize(bytes);
|
||||
} catch (Exception e) {
|
||||
log.warn("object序列化出错,可能不是object类型,使用string序列化,exception:{}",e.getMessage());
|
||||
return super.deserialize(bytes);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user