JFinal加载shiro插件,出现ehcache异常
@小鲅鱼 你好,想跟你请教个问题:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
换ehcache-core-2.4.8.jar 试试
项目中有多个ehcache的配置文件时,第一个引用的配置文件一定要有默认的缓存如:
我重启了下电脑。。。。它就好了。。。 不知道闹得是哪出。不过这个问题,我感觉是存在。 遇到过三四次。然后不就不知道所以然的就好了。。
@玛雅牛
我现在没有用EhCache,使用的是shiro内置的实现,我的shiro.ini配置如下,可以参考: