相关疑难解决方法(0)

在没有XML的情况下在Spring 4中使用EhCache

有没有办法在Spring 4或Spring Boot中初始化没有xml的EhCache?

我注意到Spring Boot 1.0.0.RC3没有任何ehcache依赖,但Spring 4.0GA发布文章提到它改进了对EhCache的支持.此外,Spring 3有类,org.springframework.cache.ehcache.EhCacheCacheManager但它不再是依赖项的一部分.

编辑: Spring 4确实有EhCache支持.您必须添加依赖项:

<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
Run Code Online (Sandbox Code Playgroud)

编辑2: 我尝试了以下内容,我认为我很接近但是我收到了一个错误:

@Bean
@Override
public CacheManager cacheManager() {
    CacheConfiguration cacheConfiguration = new CacheConfiguration();
    cacheConfiguration.setName("primary");
    cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
    cacheConfiguration.setMaxEntriesLocalHeap(0);

    net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
    config.addCache(cacheConfiguration);

    net.sf.ehcache.CacheManager cacheManager = new net.sf.ehcache.CacheManager(config);
    cacheManager.setName("EhCache");

    return new EhCacheCacheManager(cacheManager);
}

@Bean
public EhCacheManagerFactoryBean factoryBean() {
    return new EhCacheManagerFactoryBean();
}
Run Code Online (Sandbox Code Playgroud)

错误

Caused by: net.sf.ehcache.CacheException: Another unnamed CacheManager already exists in the same VM. Please provide unique names for each CacheManager in the …
Run Code Online (Sandbox Code Playgroud)

java spring ehcache

34
推荐指数
2
解决办法
5万
查看次数

在一起运行时,eclipse中的JUnit测试失败

我有一组44个JUnit测试,我使用Eclipse运行(我从其他人那里得到了这些测试 - 我是JUnit测试的新手).当我一起运行它们时,其中24个失败.但是,如果我然后单独运行失败的那些,那么其中一些确实会通过.测试确实需要一些时间 - 其中一个失败的例子需要大约一到两分钟才能完成,而只需要让它们在几秒钟内完成.

我通过右键单击它们所在的文件夹并选择"Run As - > JUnit Test"来启动多个测试.我正在使用JUnit 3.我在启动时做错了/是否有某种选项我不知道?

eclipse junit

7
推荐指数
3
解决办法
9638
查看次数

Apache Shiro EhCache初始化异常:另一个未命名的CacheManager已经存在于同一个VM中

我试图让EhCache配置为在我启用Apache Shiro的Web服务中处理授权缓存.目前我收到以下异常:

org.apache.shiro.cache.CacheException:net.sf.ehcache.CacheException:另一个未命名的CacheManager已存在于同一个VM中.请为配置中的每个CacheManager提供唯一的名称,或执行以下操作之一:
1.使用其中一个CacheManager.create()静态工厂方法重用相同名称的相同CacheManager,或者在必要时创建一个
.2.在创建之前关闭先前的cacheManager新的同名.

我的shiro.ini看起来像:
[main]
...
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager cacheManager.cacheManagerConfigFile = classpath:ehcache.xml
securityManager.cacheManager = $ cacheManager

从这个StackOverflow帖子看来,使用Spring的人通过强制CacheManager成为一个单例来解决这个问题:另一个未命名的CacheManager已经存在于同一个VM中(ehCache 2.5).

有没有人知道没有使用Spring初始化的解决方法(我在dropwizard框架内工作而不需要使用Spring)?是否有某种方式从shiro.ini强制执行单例配置?

先感谢您!

apache ehcache shiro

5
推荐指数
1
解决办法
4531
查看次数

同一虚拟机中已经存在另一个名为“ cacheManager”的CacheManager

使用ehcache和Spring启动tomcat时收到此错误。

Another CacheManager with same name 'cacheManager' already exists in the same VM. Please 
provide unique names for each CacheManager in the config or do one of following:
1. Use one of the CacheManager.create() static factory methods to reuse same
   CacheManager with same name or create one if necessary
2. Shutdown the earlier cacheManager before creating new one with same name.
Run Code Online (Sandbox Code Playgroud)
  • 春季3.1
  • ehcache 2.9.0
  • 没有使用此的测试上下文。
  • 这是一个Web JSF应用程序。

ehcache.xml

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

    </ehcache>
Run Code Online (Sandbox Code Playgroud)

cache-context.xml

        <bean …
Run Code Online (Sandbox Code Playgroud)

spring caching ehcache

5
推荐指数
1
解决办法
6701
查看次数

标签 统计

ehcache ×3

spring ×2

apache ×1

caching ×1

eclipse ×1

java ×1

junit ×1

shiro ×1