wiosenne testy: Inny CacheManager o tej samej nazwie „myCacheManager” już istnieje w tej samej maszynie wirtualnej

Zanim oznaczysz to jako duplikat, przeczytaj najpierw pytanie. Przeczytałem wszystkie informacje na temat tego wyjątku, ale nie rozwiązuje to mojego problemu. I dostaję nieco inny wyjątek, npAnother CacheManager with same name 'myCacheManager' already exists zamiastAnother unnamed CacheManager already exists.

Wiosenna konfiguracja:

<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"/>

ehcache

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
        updateCheck="false" name="myCacheManager">

</ehcache>

Problem polega na tym, że mam 1 (w przyszłości więcej) klas testowych, które testują bezpieczeństwo. klasy te ładują również plik SecurityContext.xml

Większość klas testowych ma te adnotacje:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:ApplicationContext.xml")

Jednak klasa powodująca problem:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
    "classpath:ApplicationContext.xml",
    "classpath:SecurityContext.xml"
})

Wydaje się, że lokalizacje są różne, kontekst jest ładowany ponownie, ale ehcacheManager jest nadal aktywny z poprzedniego testu.

Uwaga: dzieje się to tylko podczas uruchamiania wielu testów (np. Takich jak clean + build). Uruchomienie tej klasy testowej działa doskonale.

W czym problem? Jak mogę to rozwiązać?

questionAnswers(3)

yourAnswerToTheQuestion