Before you mark this as a duplicate, first read the question. I read all the materials about this exception, but this does not solve the problem for me. And I get a slightly different exception, like Another CacheManager with same name 'myCacheManager' already exists instead of Another unnamed CacheManager already exists .
Spring config:
<cache:annotation-driven cache-manager="cacheManager"/> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="ehcache"/> <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:configLocation="ehcache.xml" p:cacheManagerName="myCacheManager" p:shared="true"/>
Ehache
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" updateCheck="false" name="myCacheManager"> </ehcache>
The problem is that I have 1 (in the future more) test classes that test security. these classes also load SecurityContext.xml
Thus, most test classes have the following annotations:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:ApplicationContext.xml")
However, the class causes a problem:
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:ApplicationContext.xml", "classpath:SecurityContext.xml" })
It looks like in different places the context is loading again, but ehcacheManager is still active from the previous test.
Note: this only happens when running several tests (for example, as clean + build). Running this test class separately works fine.
What is the problem? How can I solve it?
source share