これは、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 が同時に実行されている可能性はありますか?
これは、Sping 3.1.1 を使用してキャッシュ マネージャーを構成する方法です。cacheManager のスコープを明示的に「シングルトン」に設定します
<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;
....
}
私のコードベースで 1 つの cacheManager しか扱っていないことは確かです。他の何かがおそらく n 番目のインスタンスを実行しています。