项目情况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
请问有人知道如何解决吗?或者问题产生的原因吗?
Shiro
Ehcache
Apache Struts
你配置 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”/>
是不是你配置了hibernate ehcache有二级缓存?
实际上,错误的信息就提示你了CacheManager这个实例,在jvm中只能存在一个,spring cache及hibernate及shiro的都的缓存中,都用这个实例就行了