【发布时间】:2017-02-23 17:22:03
【问题描述】:
当我尝试从缓存中获取数据列表时遇到问题。
CategoryServiceImpl:
@Service
@Transactional
public class CategoryServiceImpl implements CategoryService {
@Resource
private CategoryRepository categoryRepository;
@Override
@Caching(
put = {
@CachePut(value = "category", key = "'findByParrentId-' + #category.parentId + ',' + #category.user.userId"),
@CachePut(value = "category", key = "'findAll-' + #category.user.userId")
}
)
public Category add(Category category) {
return categoryRepository.saveAndFlush(category);
}
@Override
@Cacheable(cacheNames = "category", key = "'findByParrentId-' + #prntId + ',' + #userId")
public List<Category> findByParentId(long prntId, long userId) {
return categoryRepository.findByParentId(prntId, userId);
}
@Override
@Cacheable(cacheNames = "category", key = "'findAll-' + #userId")
public List<Category> findAll(long userId) {
return categoryRepository.findAll(userId);
}
}
当我尝试获取类别列表时:
List<Category> categories = new ArrayList<>(categoryService.findByParentId(parentId, userSession.getUser().getUserId()));
我得到一个例外:
ClassCastException: ru.mrchebik.model.Category 无法转换为 java.util.List
完整的堆栈跟踪:http://pastebin.com/35A14ZW9
【问题讨论】: