Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Spring中使用Ehcache中的BlockingCache?_Java_Spring_Ehcache_Ehcache 2 - Fatal编程技术网

Java 如何在Spring中使用Ehcache中的BlockingCache?

Java 如何在Spring中使用Ehcache中的BlockingCache?,java,spring,ehcache,ehcache-2,Java,Spring,Ehcache,Ehcache 2,我想在某个时候为多个请求实现一个阻塞缓存 目前我有: 在文件AppConfig.java中,我定义了缓存管理器 @EnableCaching @Configuration public class AppConfig implements WebMvcConfigurer { @Bean public CacheManager cacheManager() { return new EhCacheCacheManager(Objects.requireNonNu

我想在某个时候为多个请求实现一个阻塞缓存

目前我有:

在文件
AppConfig.java
中,我定义了缓存管理器

@EnableCaching
@Configuration
public class AppConfig implements WebMvcConfigurer {

    @Bean
    public CacheManager cacheManager() {
        return new EhCacheCacheManager(Objects.requireNonNull(ehCacheCacheManager().getObject()));
    }

    @Bean
    public EhCacheManagerFactoryBean ehCacheCacheManager() {
        EhCacheManagerFactoryBean cacheManagerFactoryBean = new EhCacheManagerFactoryBean();
        cacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
        cacheManagerFactoryBean.setShared(true);
        return cacheManagerFactoryBean;
    }
}
以下是文件中的BlockingCache定义:
BlockingCachedDecoratorFactory.java

@Component
public class BlockingCacheDecoratorFactory extends CacheDecoratorFactory {

    public Ehcache createDecoratedEhcache(final Ehcache cache, final Properties properties) {
        return new BlockingCache(cache);
    }

    public Ehcache createDefaultDecoratedEhcache(final Ehcache cache, final Properties properties) {
        return new BlockingCache(cache);
    }
}
我从
resources
xml配置文件
ehache.xml
中添加了decorator

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

    <cache name="findConcurrentById"
           eternal="false"
           maxEntriesLocalHeap="20000"
           timeToLiveSeconds="1800"
           memoryStoreEvictionPolicy="LRU">
        <cacheDecoratorFactory class="com.site.configuration.BlockingCacheDecoratorFactory"/>
    </cache>
</ehcache>

我想在方法中检索缓存

@Cacheable(value = "findConcurrentById", key = "#id", condition = "#result != null")
public Optional<Concurrent> findBy(Long id) {
    return concurrentRepo.findBy(id);
}
@Cacheable(value=“findConcurrentById”,key=“#id”,condition=“#result!=null”)
公共可选findBy(长id){
返回concurrentRepo.findBy(id);
}
但还是不行。 我所读到的只是解释了我已经实现的东西。 有人能解释一下我的代码出了什么问题吗