简体   繁体   English

应用程序上下文中用于可缓存注释的类Bean

[英]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.

相关问题 Spring 的 Cacheable Annotation 如何为通过 new 关键字初始化的类工作。 (在类构造函数中,通过 Bean 初始化) - How Spring's Cacheable Annotation can work for class initailized through new Keyword. (In a Class Constructor, initialized through Bean) 使用注入的bean方法的返回值作为@Cacheable批注中的键 - Using Injected bean method return value as key in @Cacheable annotation 应用上下文bean - Application context bean 为什么从非bean类的方法调用可缓存方法时@Cacheable不起作用 - Why @Cacheable not working when calling cacheable method from method of non bean class 从groovy类中的应用程序上下文中获取spring bean - Get spring bean from application context in groovy class 将运行时生成的类 bean 添加到 spring boot 应用程序上下文 - Add runtime generated class bean to spring boot application context 我们可以类型转换应用程序上下文获取bean作为类<?> - Can we typecast the application context get bean as Class<?> 为什么@Autowired批注将同一类的每个bean关联到context.xml? - Why @Autowired annotation associate every bean of the same class into context.xml? Spring Boot 中的可缓存注解 - Cacheable Annotation in Spring Boot @Cacheable 注解放在哪里 - Where to put @Cacheable annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM