【问题标题】:@Cacheable not working@Cacheable 不工作
【发布时间】:2015-09-10 09:45:15
【问题描述】:

我在 Spring 3.2 的 Service 层使用 @Cacheable 来缓存方法的结果。服务类内部使用以下方法代码:

@Cacheable("questions")
public List<ABClassObject> getSecutityQuestionsList(){
 List<ABClassObject> list = new ArrayList<ABClassObject>();
  ----------------
 list = ----[DAO call]

return list;

}

xml配置

    <cache:annotation-driven />

  <!-- Generic cache manager based on the JDK ConcurrentMap -->
      <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
        <property name="caches">
          <set>
            <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="questions" />
          </set>
        </property>
      </bean>

由于使用 jdk 1.6,无法使用 EhCache。 通过使用上述代码模式,我无法缓存 List 结果。当我调用上述方法时,DAO 一直被调用。 所以,建议我代码有什么问题。

提前致谢。

【问题讨论】:

    标签: java spring spring-aop spring-3


    【解决方案1】:

    您应该检查的一些事项:

    1. getSecutityQuestionsList 方法的类是一个 spring bean,也就是说,无论如何您都不要使用 new 运算符。
    2. getSecutityQuestionsList 方法是从另一个 bean 调用的
    3. 在您的 xml 配置中放置一个上下文:component-scan base-package="xxxxx"
    4. 在您的方法中放置一个断点。在堆栈跟踪中,您应该看到一些 spring 代理的东西。当您调用服务的此方法时,您实际上应该调用的是 spring 代理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-29
      • 1970-01-01
      • 2018-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多