- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在使用EhCache
在我的项目中实现一些缓存。我已经将以下依赖项添加到我的pom.xml中
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ehcache/ehcache -->
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.3.1</version>
</dependency>
EhCache
。在网上找到的所有教程中,组ID是不同的。我更改组ID的原因是它已移至
org.ehcache
。
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true"
monitoring="autodetect"
dynamicConfig="true">
<diskStore path="java.io.tmpdir"/>
<cache name="cardTypes"
maxEntriesLocalHeap="100"
maxEntriesLocalDisk="1000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU"
transactionalMode="off">
<persistence strategy="localTempSwap"/>
</cache>
</ehcache>
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.cache.CacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.core.io.ClassPathResource;
@EnableCaching
@Configuration
public class CacheConfig {
@Bean
public CacheManager cacheManager() {
return new EhCacheCacheManager(ehCacheCacheManager().getObject());
}
@Bean
public EhCacheManagerFactoryBean ehCacheCacheManager() {
EhCacheManagerFactoryBean factory = new EhCacheManagerFactoryBean();
factory.setConfigLocation(new ClassPathResource("ehcache.xml"));
factory.setShared(true);
return factory;
}
}
return new EhCacheCacheManager(ehCacheCacheManager().getObject());
The type net.sf.ehcache.CacheManager cannot be resolved. It is indirectly referenced from required .class files
Error:(21, 71) java: cannot access net.sf.ehcache.CacheManager
class file for net.sf.ehcache.CacheManager not found
ehcache
已移至
org.ehcache
。
net.sf.ehcache
有关,它不是我添加的依赖项的一部分。
最佳答案
Ehcache 2在net.sf.ehcache
包中。大多数教程都是关于它的,因为它具有很长的使用生命周期。您配置的版本Ehcache 3是全新的(但当然更好),并且在org.ehcache
包中。
该软件包之所以搬迁是因为拥有自己的域名更好,而且还因为新版本有很大的不同,并且有必要能够与旧版本同居(因为某些框架正在使用它)。
您的错误来自EhCacheCacheManager
使用Ehcache2。Ehcache3不需要它,因为它符合JCache。因此,您可以改用JCacheCacheManager
。
因此,现在,您具有Spring接线和Ehcache 2的ehcache.xml
,并且具有对Ehcache 3的依赖关系。您应该对齐它们以解决问题。
要使用Ehcache 3,最简单的方法是将其添加到application.properties
中
spring.cache.jcache.config=ehcache.xml
@EnableCaching
@Configuration
public class CacheConfig {
}
关于maven - 无法访问net.sf.ehcache.CacheManager,找不到net.sf.ehcache.CacheManager的类文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44341553/
使用 ehcache 和 Spring 启动 tomcat 时收到此错误。 Another CacheManager with same name 'cacheManager' already exi
我正在尝试在我的应用程序中使用 Ehcache 管理器。我想在没有 xml 配置的情况下设置它。我有下一个依赖项: org.ehcache ehcache 3.6.0
我要使用 CacheManager对于我的 .net 项目。问题是我找不到 CacheManager.Memcached 用法的任何示例。 我是这样用的: public class GlobalCac
我注意到根据文档,要创建缓存,您必须实例化或获取 CacheManager 并将缓存添加到其中。 singletonManager = CacheManager.create(); Cache mem
我有一个简单的 API,我的客户可以在独立应用程序中使用它。我的 API 在幕后使用 Ehcache 来提高性能。 一切正常,除了我的客户端需要在 API 中调用 shutdown() 方法来调用 C
尝试在我的 Spring 应用程序中的 Controller 上运行单元测试。 我的测试类: @RunWith (SpringJUnit4ClassRunner.class) @WebAppConfi
我已经创建了一个 nopCommerce v3.5 插件,并希望在 Controller Action 下加载一个文本文件到 _cacheManager 然后在下一个中重用它请求。 但是 _cache
使用 CacheManager ,您如何最好地实现这种情况,其中缓存实例包含可能需要很长时间才能从慢速来源获取的数据? 我从不希望用户等待缓存填充(我不关心第一次加载) 我可以想到两种方法,但不确定它
我一直在尝试使用 CacheManager缓存一些http请求,但每次都因空指针异常而失败。后一些挖掘我相信我找到了原因: CacheManager.getCacheFileBaseDir() 总是返
我正在使用 Spring Boot 和 EhCache 开发日历应用程序。我正在尝试缓存以下方法: @Override @Cacheable(value = "concerts") public Li
如何在我的应用程序的任何部分获取对 Shiro 框架中的 cacheManager 对象的引用?例如,我想删除在删除用户或更新其权限期间缓存的旧用户数据。现在我正在按照以下方式处理它 public v
我正在使用 redis 作为我的 spring 缓存实现。官方文档说我们应该像这样配置缓存管理器: 当 jedis 版本 = 2.0.0 和 spring-data-redis 版本 = 1.0.
有人可以确认 CacheManager.Net 是否支持 redis 流水线吗? 我在 documentation 中找不到它 非常感谢。 干杯,你 最佳答案 有点。CacheManager 不直接支
从 CacheManager.NET 的角度来看,我有一个关于 Redis 连接参数的基本问题。如果我们的 Redis 集群有一个主节点和两个从节点,并且有哨兵进程的法定人数,我们是否应该提供指向哨兵
我没有找到 CacheManager bean...但是我没有尝试对 CacheManager 做任何事情! 这是我的错误! org.springframework.beans.factory.Bea
net.sf.ehcache.CacheManager.ALL_CACHE_MANAGERS 是否有替代品?在 org.ehcache ehcach
根据Ehcache ,一个应用程序可以有多个CacheManager。由于可以在单个 CacheManager 中维护多个缓存,那么拥有多个 CacheManager 会给我们带来什么好处呢? Dis
我的 application.yml 中有一个默认的 redis 缓存配置: cache: type: redis redis: time-to-live: 7200000
当我使用单元测试缓存移动来测试我的应用程序时,效果很好。但是当我尝试通过功能测试来测试我的 api 时,我遇到了一个异常。 public function testGet() { Cache:
我在尝试使用 Guice 在 Play Framework 2.4.6 中进行 Controller 测试时遇到了标题所示的错误。它发生在 Controller 中的任何 view.render 代码
我是一名优秀的程序员,十分优秀!