[英]Class bean in application context for Cacheable annotation
I'm using Spring 4.1.4 and Ehcache 2.9 and caching using the @Cacheable
annotation. 我正在使用Spring 4.1.4和Ehcache 2.9,并使用
@Cacheable
批注进行缓存。
I've noticed that every public class that has a method with this annotation must be referenced in 我注意到,每个具有此批注方法的公共类都必须在
applicationContext.xml
applicationContext.xml中
as follows 如下
<bean class="com.example.web.Test"/>
this forces me to add every public class that i want to cache into the applicationContext. 这迫使我将要缓存的每个公共类添加到applicationContext中。
Is there a way to overcome this? 有办法克服吗?
Thanks 谢谢
Of course @Cacheable
works only for spring beans. 当然,
@Cacheable
仅适用于spring bean。
There are many ways to instantiate a spring bean, explicite xml configuration <bean class="..."/>
is only one. 有很多实例化spring bean的方法,显式xml配置
<bean class="..."/>
只是一个。 An other way is to enable the component scan and annotate the class with @Component
or @Service
(or some other) annotations. 另一种方法是启用组件扫描并使用
@Component
或@Service
(或其他一些)注释对类进行注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.