java定义通用接口_java – 是否可以定义通用接口并使用Spring @CacheConfig?

受到this answer的启发,我试图做到以下几点

@NoRepositoryBean

public interface CacheableRepository

extends JpaRepository, JpaSpecificationExecutor, PagingAndSortingRepository {

@Cacheable()

T findOne(ID id);

@Cacheable()

List findAll();

@Cacheable()

Page findAll(Pageable pageable);

@CacheEvict(allEntries = true)

S save(S entity);

@CacheEvict(allEntries = true)

void delete(ID id);

}

然后使用此接口定义Used存储库

@CacheConfig(cacheNames={"uniqueCache"})

public interface SomeObjectRepo extends CacheableRepository {

@Cacheable(key = "someobject+#p0")

List findByType(Integer type);

@Cacheable(key = "someobject+#p0")

List findByCategory(String field);

@Cacheable(key="someobject+#p0.concat(#p1)")

List findByCategoryAndWizardType_id(String field,Integer id);

}

作品:

上面的缓存适用于findByType,findByCategory,findByCategoryAndWizardType_id

不起作用:

对于CacheableRepository中定义的所有可缓存方法.似乎SomeObjectRepo上的CacheConfig注释不会影响CacheableRepository.

我的问题:

为什么注释不起作用?是否有解决方法使这个结构工作?

谢谢,

橡木

解决方法:

是的,当我们试图支持那种情况时,这就是奥利和我发现的东西.

我建议你在spring数据项目中创建一个问题来请求该功能.

标签:java,spring,spring-data-jpa,spring-cache,spring-data-redis

来源: https://codeday.me/bug/20190702/1357676.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值