2

こんにちは、アプリケーションにアノテーション ベースの ehcache を実装しています。これをサービスレイヤーに実装していて、クエリに DetachedCriteria を使用していますが、ehcache が機能していません。誰でもこれについて何か考えがありますか? 私を助けるか、これを行うための他の方法を提案してください。前もって感謝します

ehcache.xml 内

    <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);

そしてapplicationContext.xmlでは、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>
4

1 に答える 1

0

次の手順を実行していただければ幸いです。
1. 適切な構成のehcache.xmlファイルが必要です。サンプルはここ
にあります 。 2. springapplicationcontext.xmlで、beans タグに正しいxsdを追加したかどうかを確認します。
正しい構成の例を以下に示します。

<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>

今あなたの方法で@Cacheableof を使用してくださいimport com.googlecode.ehcache.annotations.Cacheable;

これは私のアプリからのもので、動作するはずです。

于 2013-03-08T18:02:16.697 に答える