@@@@@ @@@@@@@@

问题描述 投票:0回答:1
对,如果我的问题不是新问题,但我找不到答案。我使用Spring Data JPA和Spring Cache。我有以下仓库

@CacheConfig(cacheNames = "Category") @Cacheable @Repository public interface Repository extends CrudRepository<Category, Long> { Category findByCategory(String Category); }

而且我想缓存默认的CrudRepository方法,例如findAll()等。如果我像这样覆盖它们,那就行了

@CacheConfig(cacheNames = "Category") @Cacheable @Repository public interface Repository extends CrudRepository<Category, Long> { Category findByCategory(String Category); List<Category> findAll(); }

但是每次为每个存储库都覆盖它们并不方便。 

是否有一种方法可以缓存默认的Spring jpa方法而不会覆盖它们,或者没有这样的方法?

对,如果我的问题不是新问题,但我找不到答案。我使用Spring Data JPA和Spring Cache。我有以下存储库@CacheConfig(cacheNames =“ Category”)@Cacheable @Repository public ...

spring spring-data-jpa spring-cache
1个回答
0
投票
是的,我们可以做到。基本上,Spring使用Hibernate ORM作为JPA的实现。 Hibernate本身支持缓存功能,并且将比Spring Cache更好地集成。
© www.soinside.com 2019 - 2024. All rights reserved.