<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;
}
Comment From: snicoll
Looks related to #9734 and the new RedisCacheManager
.
@mp911de have you changed the way the default serializer is built on your side?
@javamonkey this probably happens because you are using devtools.
Comment From: javamonkey
https://github.com/javamonkey/rediscachetest
this simple project can reproduce this issues
Comment From: mp911de
Yes, it's caused by/related to #9734. We're configuring a JDK serializer/deserializer without passing a class-loader. RedisCacheConfiguration
should get configured with a JdkSerializationRedisSerializer
that has the class loader set.
Comment From: davidljuba15031979
https://github.com/spring-projects/spring-boot/issues/9444
https://stackoverflow.com/questions/37977166/java-lang-classcastexception-dtoobject-cannot-be-cast-to-dtoobject