由于想给 findAll(Pageable pageable)加上spring的缓存(spring cache),第一遍查询正常,但是在第二遍以后,从缓存中读取时,无法反序列化,提示没有无参构造,请问这个有解决办法吗?
如下:
@CacheConfig(cacheNames = {"familyUserDao"})
public interface FamilyUserDao extends JpaRepository<FamilyUser,Long> {
@Override
@Cacheable(key = "methodName +#p0")
Page<FamilyUser> findAll(Pageable pageable);
}
调用 :
Page<FamilyUser> familyUserPage = familyUserDao.findAll(pageable);
时,报:
org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Can not construct instance of org.springframework.data.domain.PageImpl: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [B@7fae8571; line: 1, column: 46]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.springframework.data.domain.PageImpl: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [B@7fae8571; line: 1, column: 46]
at org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer.deserialize(Jackson2JsonRedisSerializer.java:73),
这里其实是反序列化问题,jpa默认是使用PageImpl实现Page,
但是PageImpl并没有无参构造,如下:
有办法完美解决吗?
没有C币,一是分享问题,二是只能乞求大家看看有没有好办法啦,多谢啦