+
 新版

使用shiro和ehcache整合时候,登陆出现异常,求救

猴子 发布于 2012/02/27 18:38
阅读 37K+
收藏 1
项目情况struts2 

然后使用shiro安全框架

shiro.ini:

[main]
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
#realm
myRealm = com.haiersoft.shiro.realm.MyShiroRealm
myRealm.credentialsMatcher = $sha256Matcher

sessionManager = org.apache.shiro.web.session.mgt.DefaultWebSessionManager
securityManager.sessionManager = $sessionManager
securityManager.sessionManager.globalSessionTimeout = 360000

sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
securityManager.sessionManager.sessionDAO = $sessionDAO
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
securityManager.cacheManager = $cacheManager
然后缓存配置:

ehcache.xml

<ehcache>
<diskStore path="java.shm.tmpdir" />
<cache name="shiro-activeSessionCache" maxElementsInMemory="10000"
overflowToDisk="true" eternal="true" timeToLiveSeconds="0"
timeToIdleSeconds="0" diskPersistent="true"
diskExpiryThreadIntervalSeconds="600" />
</ehcache>

出现异常为:

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.shiro.cache.CacheException: 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: InputStreamConfigurationSource [stream=java.io.ByteArrayInputStream@13acb3d]

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.1 logs.

GlassFish Server Open Source Edition 3.1.1

请问有人知道如何解决吗?或者问题产生的原因吗?

以下是问题补充:

@猴子:今天出现一个情况,我之前在ehcache.xml配置过一个shirocache的缓存。但是我现在的缓存名字"shiro-activeSessionCache"。。为什么启动的时候加载缓存的时候他打的日志是这样的。 INFO] - [2012-02-28 09:11:11,495] - [Cache with name 'shiroCache' does not yet exist. Creating now.] - org.slf4j.impl.JCLLoggerAdapter.info(JCLLoggerAdapter.java:284) 信息: <2012-02-28 09:11:11,495> <INFO > <org.apache.shiro.cache.ehcache.EhCacheManager> - Cache with name 'shiroCache' does not yet exist. Creating now.(JCLLoggerAdapter.java:info:284) [INFO] - [2012-02-28 09:11:11,496] - [Added EhCache named [shiroCache]] - org.slf4j.impl.JCLLoggerAdapter.info(JCLLoggerAdapter.java:263) 信息: <2012-02-28 09:11:11,496> <INFO > <org.apache.shiro.cache.ehcache.EhCacheManager> - Added EhCache named [shiroCache](JCLLoggerAdapter.java:info:263) (2012/02/28 09:14)
加载中
0
纯天然原味酱
纯天然原味酱

你配置 cacheManager 的时候如果没有显示指定 cacheManagerConfigFile,那么shiro将使用“classpath:org/apache/shiro/cache/ehcache/ehcache.xml”;

而 hibernate 将会加载你上面配置的那个ehcache.xml。

要解决同时有两个未命名的cacheManager

重新指定shiro cacheManager.cacheManagerConfigFile 的值为你自己配置的ehcache.xml

或者

在你自己配置的ehcache.xml 的 <ehcache/> 配置节指定一个name属性即<ehcache name=“xxx”/>

0
PaulWong
PaulWong
shiroCacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
securityManager.cacheManager = $shiroCacheManager
0
猴子
猴子
这个写法和我写的一样啊,没什么区别。。我按照你写的改了,也是出现这个错误。。
0
PaulWong
PaulWong
将这个ehcache.xml 换成另外的名字:ehcache-shiro.xml 再看看哪报错。
0
lixuenong
lixuenong

是不是你配置了hibernate ehcache有二级缓存?

i十十
i十十
我是同时用了spring cache 和hibernate二级缓存,也报Another unnamed CacheManager already exists in the same VM 的错。请问你知道怎么解决吗?
0
lixuenong
lixuenong

实际上,错误的信息就提示你了CacheManager这个实例,在jvm中只能存在一个,spring cache及hibernate及shiro的都的缓存中,都用这个实例就行了

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部