Closed
Description
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.M7</version>
</parent>
when i first access the method getMenu,everything is fine. menu object is cached to redis server. but when i call it again,i get the following exception:
java.lang.ClassCastException: com.bee.sample.ch14.entity.Menu cannot be cast to com.bee.sample.ch14.entity.Menu
at com.sun.proxy.$Proxy68.getMenu(Unknown Source) ~[na:na]
at com.bee.sample.ch14.controller.AdminCrontroller.getMenu(AdminCrontroller.java:28)
but 2.0.0.M2 is work well.
i guess there is something wrong with JdkSerializationRedisSerializer has null classloader . If i construct JdkSerializationRedisSerializer whit Thread.currentThread().getContextClassLoader(),It work!!!
@Bean
public RedisCacheManager getRedisCacheManager(RedisConnectionFactory connectionFactory){
RedisCacheWriter cacheWriter = RedisCacheWriter.lockingRedisCacheWriter(connectionFactory);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer(loader);
SerializationPair<Object> pair = SerializationPair.fromSerializer(jdkSerializer);
RedisCacheConfiguration cacheConfig = RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(pair);
..... //ignore
return cacheManager;
}