2015-12-21 19 views
0

我有一個休眠和MySQL的春天休息應用程序。Ehcache在Spring中找不到名字?

服務的ehcache在tomcat中測試並失敗。

春天的Ehcache

<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager"> 
     <property name="cacheManager" ref="ehcache" /> 
    </bean> 
    <bean id="ehcache" 
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> 
     <property name="configLocation" value="classpath:ehcache/cache.xml" /> 
     <property name="shared" value="true" /> 
    </bean> 

語境

<cache:annotation-driven /> 
<context:component-scan base-package="com.example" /> 
    ... 
<import resource="classpath:spring/spring-cache.xml" /> 

Cache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" 
monitoring="autodetect" dynamicConfig="true" maxBytesLocalHeap="150M"> 

    <diskStore path="java.io.tmpdir" /> 

    <cache name="byCategory" eternal="false" diskSpoolBufferSizeMB="20" 
    timeToIdleSeconds="300" timeToLiveSeconds="600" 
    memoryStoreEvictionPolicy="LFU" transactionalMode="off"> 

    </cache> 
</ehcache> 

休眠緩存只有在PROD

<prop key="hibernate.cache.use_query_cache">true</prop> 
    <prop key="hibernate.cache.use_second_level_cache">true</prop> 
    <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop> 
    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory 
    </prop> 

我有一個門面與一個mtehod具有註釋

@Cacheable(值= { 「byCategory」},鍵= 「#ids.toString()」 )

這個測試運行正常,因爲沒有使用hibernate ehcache,但在prod中CacheManager不加載我在xml中定義的名稱。

可以合併hibernate和owns的名稱嗎?

+0

Hibernate和Spring基於緩存是不同的東西,因此緩存是不共享的。 –

回答

0

您應該可以在同一應用程序中使用多個CacheManager

請確保它們有不同的名稱。根據您的設置,通過命名您使用classpath:ehcache/cache.xml配置的CacheManager可能會首先進行測試。

類似下面應該做的伎倆:

<ehcache name="aName" 
    <!-- Your configuration --> 
</ehcache>