我想使用spring缓存,并将其添加到findAll(Pageable pageable)上,如下所示:
@CacheConfig(cacheNames = {"familyUserDao"})
public interface FamilyUserDao extends JpaRepository<FamilyUser,Long> {
@Override
@Cacheable(key = "methodName +#p0")
Page<FamilyUser> findAll(Pageable pageable);
}
我打电话的时候
页面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)
实际上这是一个反序列化问题,Page的默认实现类是PageImpl。但是它没有默认的构造函数,那么如何解决呢?
答案 0 :(得分:0)
在调用方法时,您必须传递参数,这是Page类型和整数类型的两个属性,例如continuation:
Page familyUserPage = familyUserDao.findAll (int page, int size);
要显示前10个对象,请将页面置于0并将大小设为10,将10跟随页面设为1并将大小设为10 ...