有没有人使用Spring数据和Ehcache二级缓存?我在正确配置时遇到问题 .

JPA属性:

<prop key="hibernate.cache.provider_class">org.hibernate.cache.SingletonEhCacheProvider</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="net.sf.ehcache.configurationResourceName">/ad_lobby/ehcache.xml</prop>

抵抗单位:

<persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
    <properties>
        <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
</persistence-unit>

类标有Cacheable注释

但是在启动测试时:

@Test
public void testCache() {
def device = new Device()
deviceRepository.save(device)
for (int i = 0; i < 25; i++) {
    long now = new Date().getTime()
    deviceRepository.findById(device.id)
    long dif = new Date().getTime() - now
    println('Difference: ' + dif)
}
}

我有25个选择我的对象,虽然实体已被放入缓存:

second level cache puts=1
second level cache hits=0
second level cache misses=0

有任何想法吗?