运行我的JUnit测试时会发生什么...
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.
The source of the existing CacheManager is:
DefaultConfigurationSource [ ehcache.xml or ehcache-failsafe.xml ]
这个异常的原因是什么?可能会同时运行多个cacheManager吗?
这是我使用Spring 3.1.1配置cacheManager的方式。它明确将cacheManager的作用域设置为“singleton”。
<ehcache:annotation-driven />
<bean
id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
scope="singleton"
/>
ehcache.xml文件如下
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false"
maxBytesLocalHeap="100M"
name="cacheManager"
>
....
</ehcache>
最后我的类
@Component
public class BookingCache implements CacheWrapper<String, BookingUIBean> {
@Autowired
private CacheManager ehCacheManager;
....
}
我非常确定在我的代码库中只涉及一个cacheManager。可能是其他东西正在运行第n个实例。