JFinal加载shiro插件,出现ehcache异常

发布于 2021-12-01 06:21:24 字数 7652 浏览 763 评论 5

@小鲅鱼 你好,想跟你请教个问题:

http://www.oschina.net/question/96568_113153

这个里面你提到

其实在启动项目的时候shiro已经默认启动好了,如果JFinal再加载shiro,那么会出现ehcache异常,提示ehcache已经存在不能创建,



这个后来是怎么解决的?

我的错误:

[main] ERROR org.apache.shiro.web.servlet.AbstractFilter - Unable to start Filter: [Unable to set property 'cacheManager' with value [org.apache.shiro.cache.ehcache.EhCacheManager@5e20dcb7] on object of type org.apache.shiro.web.mgt.DefaultWebSecurityManager.  If 'org.apache.shiro.cache.ehcache.EhCacheManager@5e20dcb7' is a reference to another (previously defined) object, prefix it with '$' to indicate that the referenced object should be used as the actual value.  For example, $org.apache.shiro.cache.ehcache.EhCacheManager@5e20dcb7].
org.apache.shiro.config.ConfigurationException: Unable to set property 'cacheManager' with value [org.apache.shiro.cache.ehcache.EhCacheManager@5e20dcb7] on object of type org.apache.shiro.web.mgt.DefaultWebSecurityManager.  If 'org.apache.shiro.cache.ehcache.EhCacheManager@5e20dcb7' is a reference to another (previously defined) object, prefix it with '$' to indicate that the referenced object should be used as the actual value.  For example, $org.apache.shiro.cache.ehcache.EhCacheManager@5e20dcb7
	at org.apache.shiro.config.ReflectionBuilder.setProperty(ReflectionBuilder.java:501)
	at org.apache.shiro.config.ReflectionBuilder.applyProperty(ReflectionBuilder.java:450)
	at org.apache.shiro.config.ReflectionBuilder.applyProperty(ReflectionBuilder.java:562)
	at org.apache.shiro.config.ReflectionBuilder.applySingleProperty(ReflectionBuilder.java:206)
	at org.apache.shiro.config.ReflectionBuilder.applyProperty(ReflectionBuilder.java:167)
	at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:124)
	at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:161)
	at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:124)
	at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:102)
	at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:88)
	at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:46)
	at org.apache.shiro.config.IniFactorySupport.createInstance(IniFactorySupport.java:123)
	at org.apache.shiro.util.AbstractFactory.getInstance(AbstractFactory.java:47)
	at org.apache.shiro.web.servlet.IniShiroFilter.applySecurityManager(IniShiroFilter.java:260)
	at org.apache.shiro.web.servlet.IniShiroFilter.configure(IniShiroFilter.java:228)
	at org.apache.shiro.web.servlet.IniShiroFilter.init(IniShiroFilter.java:190)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.onFilterConfigSet(AbstractShiroFilter.java:152)
	at org.apache.shiro.web.servlet.AbstractFilter.init(AbstractFilter.java:97)
	at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:119)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:724)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
	at org.eclipse.jetty.server.Server.doStart(Server.java:277)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
	at com.jfinal.server.JettyServer.doStart(JettyServer.java:120)
	at com.jfinal.server.JettyServer.start(JettyServer.java:64)
	at com.jfinal.core.JFinal.main(JFinal.java:173)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2116)
	at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2097)
	at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1903)
	at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2010)
	at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1011)
	at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:454)
	at org.apache.shiro.config.ReflectionBuilder.setProperty(ReflectionBuilder.java:493)
	... 31 more
Caused by: org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Another CacheManager with same name 'shiro' 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.BufferedInputStream@575c13ef]
	at org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:224)
	at org.apache.shiro.cache.ehcache.EhCacheManager.getCache(EhCacheManager.java:156)
	at org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:245)
	at org.apache.shiro.realm.AuthorizingRealm.getAvailableAuthorizationCache(AuthorizingRealm.java:260)
	at org.apache.shiro.realm.AuthorizingRealm.afterCacheManagerSet(AuthorizingRealm.java:226)
	at org.apache.shiro.realm.CachingRealm.setCacheManager(CachingRealm.java:96)
	at org.apache.shiro.mgt.RealmSecurityManager.applyCacheManagerToRealms(RealmSecurityManager.java:115)
	at org.apache.shiro.mgt.RealmSecurityManager.afterCacheManagerSet(RealmSecurityManager.java:127)
	at org.apache.shiro.mgt.SessionsSecurityManager.afterCacheManagerSet(SessionsSecurityManager.java:103)
	at org.apache.shiro.mgt.CachingSecurityManager.setCacheManager(CachingSecurityManager.java:72)
	... 42 more
Caused by: net.sf.ehcache.CacheException: Another CacheManager with same name 'shiro' 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.BufferedInputStream@575c13ef]
	at net.sf.ehcache.CacheManager.assertNoCacheManagerExistsWithSameName(CacheManager.java:628)
	at net.sf.ehcache.CacheManager.init(CacheManager.java:392)
	at net.sf.ehcache.CacheManager.<init>(CacheManager.java:356)
	at org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:213)
	... 51 more



如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

草莓味的萝莉 2021-12-03 19:03:46

换ehcache-core-2.4.8.jar 试试

顾忌 2021-12-03 19:03:33

项目中有多个ehcache的配置文件时,第一个引用的配置文件一定要有默认的缓存如:

<!-- defaultCache -->
    <defaultCache maxElementsInMemory="3600" eternal="false" timeToIdleSeconds="10800" timeToLiveSeconds="10800" overflowToDisk="false" />

平定天下 2021-12-03 18:32:19

我重启了下电脑。。。。它就好了。。。 不知道闹得是哪出。不过这个问题,我感觉是存在。 遇到过三四次。然后不就不知道所以然的就好了。。

旧伤慢歌 2021-12-03 03:11:20

我现在没有用EhCache,使用的是shiro内置的实现,我的shiro.ini配置如下,可以参考:

[main]
#sessionId
sessionIdCookie=org.apache.shiro.web.servlet.SimpleCookie
sessionIdCookie.name=wellbole
#sessionIdCookie.domain=localhost:8080
sessionIdCookie.path=/
sessionIdCookie.maxAge=1800
sessionIdCookie.httpOnly=true

#password
passwordService = org.apache.shiro.authc.credential.DefaultPasswordService
passwordMatcher = org.apache.shiro.authc.credential.PasswordMatcher
passwordMatcher.passwordService = $passwordService

#realm
shiroDbRealm = com.wellbole.web.core.shiro.ShiroDbRealm
shiroDbRealm.credentialsMatcher = $passwordMatcher
securityManager.realms = $shiroDbRealm
authcStrategy = com.wellbole.web.core.shiro.AnySuccessfulStrategy
securityManager.authenticator.authenticationStrategy = $authcStrategy
#cache
cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $cacheManager

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文