Commit 465b6add8fa4258f1c20e72208254ad4fe18158d

Authored by ci-aliyun
1 parent 0858ede0

#fix:修复对PageHelper中拦截对象无法正常序列化的BUG

... ... @@ -6,7 +6,7 @@
6 6  
7 7 <groupId>com.irrigation</groupId>
8 8 <artifactId>common-lib</artifactId>
9   - <version>1.2.2</version>
  9 + <version>1.2.3</version>
10 10  
11 11 <properties>
12 12 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
... ... @@ -17,7 +17,7 @@
17 17 <commons-codec.version>1.11</commons-codec.version>
18 18 <guava.vsersion>20.0</guava.vsersion>
19 19 <slf4j.version>1.7.24</slf4j.version>
20   - <fastjson.version>1.2.46</fastjson.version>
  20 + <fastjson.version>1.2.49</fastjson.version>
21 21 <spring-web.version>4.3.14.RELEASE</spring-web.version>
22 22 <spring-security-core.version>4.2.4.RELEASE</spring-security-core.version>
23 23 <ehcache.version>2.6.11</ehcache.version>
... ...
src/main/java/com/irrigation/icl/cache/config/CacheConfig.java
1 1 package com.irrigation.icl.cache.config;
2 2  
3   -import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
4   -import org.springframework.boot.autoconfigure.AutoConfigureAfter;
5   -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
6   -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
7 4 import org.springframework.context.annotation.Bean;
8 5 import org.springframework.context.annotation.Configuration;
9 6 import org.springframework.data.redis.connection.RedisConnectionFactory;
10 7 import org.springframework.data.redis.core.RedisTemplate;
  8 +import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
11 9 import org.springframework.data.redis.serializer.StringRedisSerializer;
12 10  
13 11 /**
... ... @@ -17,27 +15,22 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
17 15 @Configuration
18 16 public class CacheConfig {
19 17  
  18 + @ConditionalOnMissingBean(RedisTemplate.class)
20 19 @Bean
21 20 public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
22 21 RedisTemplate<Object, Object> template = new RedisTemplate<>();
23 22 template.setConnectionFactory(connectionFactory);
24   -
25   - //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
26   -// Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);
27   -
28   - GenericFastJsonRedisSerializer serializer = new GenericFastJsonRedisSerializer();
29   -
30   -// ObjectMapper mapper = new ObjectMapper();
31   -// mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
32   -// mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
33   -// serializer.setObjectMapper(mapper);
34   -
35   - template.setValueSerializer(serializer);
  23 +// Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(Object.class);
  24 +// ObjectMapper om = new ObjectMapper();
  25 +// om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
  26 +// om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
  27 +// jackson2JsonRedisSerializer.setObjectMapper(om);
  28 +//
  29 + template.setValueSerializer(new JdkSerializationRedisSerializer());
36 30 //使用StringRedisSerializer来序列化和反序列化redis的key值
37 31 template.setKeySerializer(new StringRedisSerializer());
38 32 template.afterPropertiesSet();
39 33 return template;
40 34 }
41 35  
42   -
43 36 }
... ...
src/main/java/com/irrigation/icl/cache/core/LayeringCache.java
... ... @@ -6,21 +6,18 @@ import net.sf.ehcache.CacheException;
6 6 import net.sf.ehcache.CacheManager;
7 7 import net.sf.ehcache.Ehcache;
8 8 import net.sf.ehcache.Element;
9   -import net.sf.ehcache.config.*;
  9 +import net.sf.ehcache.config.CacheConfiguration;
  10 +import net.sf.ehcache.config.Configuration;
  11 +import net.sf.ehcache.config.DiskStoreConfiguration;
  12 +import net.sf.ehcache.config.PersistenceConfiguration;
10 13 import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
11   -import net.sf.ehcache.store.compound.ReadWriteCopyStrategy;
12 14 import org.springframework.cache.Cache;
13   -import org.springframework.cache.ehcache.EhCacheCacheManager;
14   -import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
15 15 import org.springframework.cache.support.SimpleValueWrapper;
16 16 import org.springframework.data.redis.cache.RedisCache;
17 17 import org.springframework.data.redis.core.RedisOperations;
18 18 import org.springframework.util.StopWatch;
19 19  
20   -import java.io.Serializable;
21   -import java.sql.Time;
22 20 import java.text.SimpleDateFormat;
23   -import java.time.LocalDateTime;
24 21 import java.util.Date;
25 22 import java.util.concurrent.Callable;
26 23 import java.util.concurrent.ConcurrentHashMap;
... ... @@ -33,11 +30,10 @@ import java.util.concurrent.FutureTask;
33 30 */
34 31 @Slf4j
35 32 public class LayeringCache extends RedisCache {
  33 + private final ConcurrentHashMap<String, Future<Ehcache>> layeringL1CacheContainer = new ConcurrentHashMap<>();
36 34 private LayeringCacheProperties layeringCacheProperties;
37 35 private LayeringCacheManager layeringCacheManager;
38 36 private CacheManager layeringL1CacheManager;
39   - private final ConcurrentHashMap<String, Future<Ehcache>> layeringL1CacheContainer = new ConcurrentHashMap<>();
40   -
41 37 private boolean layerL1Enable;
42 38 private String ID;
43 39 // private String HOST;
... ... @@ -63,17 +59,17 @@ public class LayeringCache extends RedisCache {
63 59 ehCache = getL1Cache(super.getName());
64 60 Element value = ehCache.get(key);
65 61 if (value != null) {
66   - log.info("Hit Cache L1 (ehcache) :{}={}", key, value);
  62 + log.debug("Hit Cache L1 (ehcache) :{}={}", key, value);
67 63 return new SimpleValueWrapper(value.getObjectValue());
68 64 }
69 65 }
70 66 Cache.ValueWrapper wrapper = super.get(key);
71 67 if (layerL1Enable && ehCache != null && wrapper != null) {
72 68 ehCache.put(new Element(key, wrapper.get()));
73   - log.info("Hit Cache L2 (redis) :{}={}", key, wrapper);
  69 + log.debug("Hit Cache L2 (redis) :{}={}", key, wrapper);
74 70 }
75 71 stopWatch.stop();
76   - log.info("get use {} ms", stopWatch.getTotalTimeMillis());
  72 + log.debug("get use {} ms", stopWatch.getTotalTimeMillis());
77 73 return wrapper;
78 74 }
79 75  
... ... @@ -90,7 +86,7 @@ public class LayeringCache extends RedisCache {
90 86 }
91 87 super.put(key, value);
92 88 stopWatch.stop();
93   - log.info("put use {} ms", stopWatch.getTotalTimeMillis());
  89 + log.debug("put use {} ms", stopWatch.getTotalTimeMillis());
94 90 }
95 91  
96 92 @Override
... ... @@ -131,11 +127,11 @@ public class LayeringCache extends RedisCache {
131 127 switch (command.getOper()) {
132 128 case Command.OPT_DEL:
133 129 getL1Cache(command.getName()).remove(command.getKey());
134   - log.info("Remove Cache L1 {} - {}", command.getName(), command.getKey());
  130 + log.debug("Remove Cache L1 {} - {}", command.getName(), command.getKey());
135 131 break;
136 132 case Command.OPT_REM:
137 133 getL1Cache(command.getName()).removeAll();
138   - log.info("Clear Cache L1 {}", command.getName());
  134 + log.debug("Clear Cache L1 {}", command.getName());
139 135 break;
140 136 case Command.OPT_SET:
141 137 Cache.ValueWrapper wrapper = super.get(command.getKey());
... ... @@ -143,7 +139,7 @@ public class LayeringCache extends RedisCache {
143 139 Ehcache ehCache = getL1Cache(super.getName());
144 140 ehCache.put(new Element(command.getKey(), wrapper.get(), false, layeringCacheProperties.getCacheL1().getLocalTimeToIdleSeconds(),
145 141 layeringCacheProperties.getCacheL1().getLocalTimeToLiveSeconds()));
146   - log.info("Update Cache L1 {} - {}", command.getKey(), wrapper.get());
  142 + log.debug("Update Cache L1 {} - {}", command.getKey(), wrapper.get());
147 143 }
148 144 break;
149 145 default:
... ...