鉴于我拥有Spring Data存储库,并且在findAll
方法上放置了Cacheable注释:
@Repository
@CacheConfig(cacheNames = TEMPLATE_CACHE)
public interface TemplateRepository extends JpaRepository<Template, Long> {
@Override
@Cacheable
List<Template> findAll();
}
Intellij IDEA显示警告:
Spring Team recommends that you only annotate concrete classes (and methods of concrete classes) with the @Cache* annotation, as opposed to annotating interfaces.
You certainly can place the @Cache* annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies.
The fact that Java annotations are not inherited from interfaces means that if you are using class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"),
then the caching settings are not recognized by the proxying and weaving infrastructure, and the object will not be wrapped in a caching proxy, which would be decidedly bad.
真的那么糟糕吗?
从实践的角度来看会发生什么?
在我想调用findAll
的情况下,该注释应放在哪里? Controller
映射?
Spring Data如何处理此问题?对我来说似乎很好。