首页 > 解决方案 > 在重复的 EHCache 上升级 Shiro 到 1.6.0 失败

问题描述

我尝试将 Spring Web 应用程序中的 Shiro 从 1.2.3 升级到 1.6.0。我刚刚修改了gradle中的版本并重新编译了war。但它没有开始:

Caused by: net.sf.ehcache.CacheException: Another unnamed 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 ]
at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:529)

我不在 Shiro 配置中使用 EHCache:

<import resource="file:${CONFIG_PATH}/ldap-realm.xml"/>

<!-- SHIRO  Access control -->
<bean id="securityManager" class="com.cgi.apps.centaur.engine.access.realm.IPOverridingSecurityManager">
    <property name="realms" ref="shiroRealms"/>
    <property name="cacheManager" ref="memoryConstrainedCacheManager"/>
    <property name="sessionManager" ref="sessionManager"/>
</bean>

<bean id="sessionManager" class="com.cgi.apps.centaur.engine.access.realm.IPOverridingSessionManager">
</bean>

<bean id="memoryConstrainedCacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"/>

问题出在哪里?

标签: javaspringehcacheshiro

解决方案


我必须明确选择 gradle 中的包。Shiro 所有导入的 ehcache 模块都有自己的捆绑包ehcache.xml,这与我的配置冲突。

compile("org.apache.shiro:shiro-core:${versionShiro}") {
    exclude group: 'org.sonatype.sisu.inject', module: 'cglib'
}
compile "org.apache.shiro:shiro-web:${versionShiro}", "org.apache.shiro:shiro-spring:${versionShiro}"

推荐阅读