在將其標記爲重複之前,請先閱讀問題。我已閱讀了有關此異常的所有內容,但它不能解決此問題。而且我確實得到了一個稍微不同的例外,例如Another CacheManager with same name 'myCacheManager' already exists
而不是Another unnamed CacheManager already exists
。彈簧測試:在同一虛擬機中已經存在另一個具有相同名稱'myCacheManager'的CacheManager
Spring配置:
<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>
的問題是,我有1(在未來更多)測試安全測試類。這些類還加載SecurityContext.xml
所以大多數測試類有這樣的註解:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:ApplicationContext.xml")
但造成問題的類:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:ApplicationContext.xml",
"classpath:SecurityContext.xml"
})
它似乎因爲位置不同的上下文再次加載,但ehcacheManager仍然是以前的測試活動。
注意:只有在運行多個測試(例如,像clean + build)時纔會發生這種情況。單獨運行這個測試類完全正常。
這是什麼問題?我該如何解決它?
問題是這種情況發生在測試運行之前,而不是之前。或者說,否則我將不得不用這個註釋標記每一個測試類,以使其工作。我需要的是類似@RunInOwnContext的東西。 – 2013-02-23 13:30:45
是的,這確實意味着你必須註釋每個測試課程......不幸的是,我沒有其他方式知道。 – jeha 2013-02-23 14:06:21
當然,你試圖以你需要的方式修改SpringJUnit4ClassRunner/TestContextManager ...但我不知道這是你真正想要的 – jeha 2013-02-23 14:15:51