Xml ehcache不工作

Xml ehcache不工作,xml,spring-mvc,ehcache,Xml,Spring Mvc,Ehcache,嗨,我正在我的应用程序中实现基于注释的ehcache。我在服务层上实现了这一点,并使用DetachedCriteria进行查询,但ehcache不起作用。有人知道这件事吗?请帮助我或建议我其他方法来做这件事。 提前谢谢 <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" /> <cache name="loadAll" maxElementsInMemory

嗨,我正在我的应用程序中实现基于注释的ehcache。我在服务层上实现了这一点,并使用DetachedCriteria进行查询,但ehcache不起作用。有人知道这件事吗?请帮助我或建议我其他方法来做这件事。 提前谢谢

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>
在ehcache.xml中

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>

在我使用的服务层上

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>
@Cacheable(cacheName="loadAll")
    List<ShiftDetail> loadAll(DetachedCriteria detachedCriteria);
@Cacheable(cacheName=“loadAll”)
列出loadAll(DetachedCriteria DetachedCriteria);
在applicationContext.xml中,ehcache映射为

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>
<ehcache:annotation-driven  create-missing-caches="true" cache-manager="cacheManager" />

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

我希望您已完成以下步骤。
1.您需要一个配置正确的ehcache.xml文件。可以找到示例
2.在springapplicationcontext.xml中,查看是否在beans标记中添加了正确的xsd
正确配置示例如下所示:

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.2.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
     http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring 
     http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd
     ">
<cache:annotation-driven />
    <bean id="cacheManager"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="/WEB-INF/xml/spring/ehcache.xml" /> 
    </bean>

</beans>

现在,在您的方法中,使用导入com.googlecode.ehcache.annotations.Cacheable的
@Cacheable

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>

这是我的应用程序,应该可以使用。

我希望您已经完成以下步骤。
    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>
1.您需要一个配置正确的ehcache.xml文件。可以找到示例
2.在springapplicationcontext.xml中,查看是否在beans标记中添加了正确的xsd
正确配置示例如下所示:

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:cache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
xsi:schemaLocation="
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.2.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
     http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring 
     http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd
     ">
<cache:annotation-driven />
    <bean id="cacheManager"
        class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
        <property name="configLocation" value="/WEB-INF/xml/spring/ehcache.xml" /> 
    </bean>

</beans>

现在,在您的方法中,使用导入com.googlecode.ehcache.annotations.Cacheable的
@Cacheable

    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>

这是我的应用程序,应该可以使用。

也许你可以显示你的代码?我用ehcache做了一点,但我不能像字母表那样反刍它。考虑点击你的问题编辑并添加一些相关的代码和配置。这将为我们提供一些背景和一些工作。祝你好运嗨,拉曼,你解决问题了吗?我和你有同样的问题,我有点疼。每次调用metodh时,它都不会创建缓存实例。这是我的问题:你到底想缓存什么?也许你可以显示你的代码?我用ehcache做了一点,但我不能像字母表那样反刍它。考虑点击你的问题编辑并添加一些相关的代码和配置。这将为我们提供一些背景和一些工作。祝你好运嗨,拉曼,你解决问题了吗?我和你有同样的问题,我有点疼。每次调用metodh时,它都不会创建缓存实例。这是我的问题:你到底想缓存什么?
    <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />

    <cache name="loadAll" maxElementsInMemory="1000" eternal="true" overflowToDisk="false" />

</ehcache>