Java Ehcache:找不到缓存

Java Ehcache:找不到缓存,java,spring,hibernate,ehcache,Java,Spring,Hibernate,Ehcache,我正在我的应用程序中使用Ehcache+Spring+Hibernte这里有一些详细信息 低于异常 原因:com.googlecode.ehcache.annotations.CacheNotFoundException: 在上找不到缓存'com.ccc.spring.model.Validuserrole' com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getCache(CacheAttributeSource

我正在我的应用程序中使用Ehcache+Spring+Hibernte这里有一些详细信息 低于异常

原因:com.googlecode.ehcache.annotations.CacheNotFoundException: 在上找不到缓存'com.ccc.spring.model.Validuserrole' com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getCache(CacheAttributeSourceImpl.java:223) 在 com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.parseCacheableAnnotation(CacheAttributeSourceImpl.java:325) 在 com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.findMethodAttribute(CacheAttributeSourceImpl.java:268) 在 com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.computeMethodAttribute(CacheAttributeSourceImpl.java:242) 在 com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute(CacheAttributeSourceImpl.java:167) 在 com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getAdviceType(CacheAttributeSourceImpl.java:122) 在 com.googlecode.ehcache.annotations.impl.CacheStaticMethodMatcherPointcut.matches(CacheStaticMethodMatcherPointcut.java:46) 在 org.springframework.aop.support.AopUtils.canApply(AopUtils.java:225) 在 org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262) 在 org.springframework.aop.support.AopUtils.FindVisorsThatCanApp(AopUtils.java:294) 在 org.springframework.aop.framework.autoproxy.AbstractAdvisoruToproxyCreator.FindVisors可应用(AbstractAdvisoruToproxyCreator.java:118) 在 org.springframework.aop.framework.autoproxy.AbstractAdvisorautorProxyCreator.findEligibleAdvisors(AbstractAdvisorautorProxyCreator.java:88) 在 org.springframework.aop.framework.autoproxy.AbstractAdvisorautorProxyCreator.GetAdvicesandAdvisorForBean(AbstractAdvisorautorProxyCreator.java:69) 在 org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:376) 在 org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:339) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:421) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1558) 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ... 还有21个

这是我的ehcache.xml文件

<ehcache>

    <defaultCache maxElementsInMemory="100" eternal="false"
        timeToIdleSeconds="120" timeToLiveSeconds="200" />
    <cache name="com.ccc.spring.model.Validuserrole" maxElementsInMemory="100"
        eternal="false" timeToIdleSeconds="5" timeToLiveSeconds="2000" />

</ehcache>

问题在于,您在Spring+EhCache集成中使用了错误的注释。您需要使用
org.springframework.cache.annotation.Cacheable
而不是
com.googlecode.ehcache.annotations.Cacheable


查看并获取有关如何使用Spring的缓存支持(由Spring 3.1引入)和EhCache作为缓存提供程序的更多信息,在bean中实现可序列化接口
并在您的
ehcache.xml
文件中写入
diskStore path=“F:/ehcache”/>
,我认为您使用了错误的缓存注释。确保从
org.springframework.cache.annotation.Cacheable
导入了
@Cacheable
。让我知道它是否适用于您我正在使用import com.googlecode.ehcache.annotations.cacheable进行我在前面的评论中提到的更改,并让我知道发生了什么。Spring的缓存支持与Google缓存支持没有任何关系它起作用了,但我正在使用这个例子,你有没有集成Spring+Hibernate+Ehcache的好例子请查看下面的答案我必须使用哪个属性值或其他东西来保存缓存,并使用某个名称@Cacheable(value={“com.ccc.Spring.model.Validuserrole”})你所描述的应该是有效的,因为注释的值是缓存的名称。“编辑问题”也添加了新方法,但它不起作用它再次从数据库中获取记录你是否正确地遵循了博客文章中的说明?是的,最大值是相同的,添加了查询,但当我们必须将项目部署到生产服务器时,这将如何工作?
<ehcache:annotation-driven />

    <ehcache:config cache-manager="cacheManager">
        <ehcache:evict-expired-elements
            interval="60" />
    </ehcache:config>

    <bean id="cacheManager"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="/WEB-INF/ehcache.xml" />

    </bean>

    <context:component-scan base-package="com.ccc.spring" />
@Cacheable(cacheName="com.ccc.spring.model.Validuserrole")
    public List<Validuserrole> getRoleList() {
        List list = getSessionFactory().getCurrentSession()
                .createQuery("from Validuserrole where active = ?")
                .setParameter(0, true).list();
        return list;
    }
@Cacheable( value = { "com.ccc.spring.model.Validuserrole" })
    public List<Validuserrole> getRoleList() {
        List list = null;
        try{
          list = getSessionFactory().getCurrentSession()
                .createQuery("from Validuserrole ").list();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return list;
    }
Hibernate: select validuserr0_.roleid as roleid15_, validuserr0_.active as active15_, validuserr0_.createdon as createdon15_, validuserr0_.roledescription as roledesc4_15_ from subodhc_ccc.validuserrole validuserr0_
Hibernate: select user0_.userid as userid11_, user0_.aboutme as aboutme11_, user0_.addressid as addressid11_, user0_.createdon as createdon11_, user0_.dikshadate as dikshadate11_, user0_.dob as dob11_, user0_.emailid as emailid11_, user0_.firstname as firstname11_, user0_.gender as gender11_, user0_.lastmodifiedby as lastmodi9_11_, user0_.lastmodifiedon as lastmod10_11_, user0_.lastname as lastname11_, user0_.middlename as middlename11_, user0_.mobilenumber as mobilen13_11_, user0_.password as password11_, user0_.phonenumber as phonenu15_11_, user0_.username as username11_, user0_.statusid as statusid11_, user0_.roleid as roleid11_ from subodhc_ccc.user user0_ where user0_.statusid=2 and user0_.roleid=4
Hibernate: select country0_.CountryId as CountryId2_, country0_.CountryName as CountryN2_2_, country0_.LastUpdate as LastUpdate2_ from subodhc_ccc.country country0_
Hibernate: select validuserr0_.roleid as roleid15_, validuserr0_.active as active15_, validuserr0_.createdon as createdon15_, validuserr0_.roledescription as roledesc4_15_ from subodhc_ccc.validuserrole validuserr0_
Hibernate: select country0_.CountryId as CountryId2_, country0_.CountryName as CountryN2_2_, country0_.LastUpdate as LastUpdate2_ from subodhc_ccc.country country0_