2015-12-21 98 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>