[ERROR]-[Thread: main]-[com.jfinal.kit.LogKit.error()]: net.sf.ehcache.CacheException: Unable to load class net.sf.ehcache.store.DefaultElementValueComparator. Initial cause was net.sf.ehcache.store.DefaultElementValueComparator.<init>(net.sf.ehcache.config.CacheConfiguration) org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: Unable to load class net.sf.ehcache.store.DefaultElementValueComparator. Initial cause was net.sf.ehcache.store.DefaultElementValueComparator.<init>(net.sf.ehcache.config.CacheConfiguration) at org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:224) at org.apache.shiro.cache.ehcache.EhCacheManager.init(EhCacheManager.java:199) at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) at org.apache.shiro.config.ReflectionBuilder$BeanConfigurationProcessor.execute(ReflectionBuilder.java:785) at org.apache.shiro.config.ReflectionBuilder.buildObjects(ReflectionBuilder.java:260) at org.apache.shiro.config.IniSecurityManagerFactory.buildInstances(IniSecurityManagerFactory.java:167) at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:130) at org.apache.shiro.config.IniSecurityManagerFactory.createSecurityManager(IniSecurityManagerFactory.java:108) at org.apache.shiro.config.IniSecurityManagerFactory.createInstance(IniSecurityManagerFactory.java:94) 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.env.IniWebEnvironment.createWebSecurityManager(IniWebEnvironment.java:203) at org.apache.shiro.web.env.IniWebEnvironment.configure(IniWebEnvironment.java:99) at org.apache.shiro.web.env.IniWebEnvironment.init(IniWebEnvironment.java:92) at jzero.base.shiro.ShiroIniWebEnvironment.init(ShiroIniWebEnvironment.java:30) at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:45) at org.apache.shiro.util.LifecycleUtils.init(LifecycleUtils.java:40) at org.apache.shiro.web.env.EnvironmentLoader.createEnvironment(EnvironmentLoader.java:221) at org.apache.shiro.web.env.EnvironmentLoader.initEnvironment(EnvironmentLoader.java:133) at org.apache.shiro.web.env.EnvironmentLoaderListener.contextInitialized(EnvironmentLoaderListener.java:58) at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:952) at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:558) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:917) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:370) at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1497) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1459) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:847) at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:287) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:138) at org.eclipse.jetty.server.Server.start(Server.java:416) at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:108) at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113) at org.eclipse.jetty.server.Server.doStart(Server.java:383) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at jzero.base.server.jetty.JettyServer.doStart(JettyServer.java:131) at jzero.base.server.jetty.JettyServer.start(JettyServer.java:52) at jzero.admin.config.MainConfig.main(MainConfig.java:61) aused by: net.sf.ehcache.CacheException: Unable to load class net.sf.ehcache.store.DefaultElementValueComparator. Initial cause was net.sf.ehcache.store.DefaultElementValueComparator.<init>(net.sf.ehcache.config.CacheConfiguration) at net.sf.ehcache.util.ClassLoaderUtil.createNewInstance(ClassLoaderUtil.java:100) at net.sf.ehcache.config.ElementValueComparatorConfiguration.getElementComparatorInstance(ElementValueComparatorConfiguration.java:59) at net.sf.ehcache.Cache.initialise(Cache.java:1040) at net.sf.ehcache.CacheManager.initializeEhcache(CacheManager.java:1258) at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1289) at net.sf.ehcache.CacheManager.addConfiguredCaches(CacheManager.java:706) at net.sf.ehcache.CacheManager.doInit(CacheManager.java:424) at net.sf.ehcache.CacheManager.init(CacheManager.java:358) at net.sf.ehcache.CacheManager.<init>(CacheManager.java:323) at org.apache.shiro.cache.ehcache.EhCacheManager.ensureCacheManager(EhCacheManager.java:213) ... 40 more
今天升级3.5后就一直报这样的错。起初以为是maven导入的包冲突导致。仔细检查后发现并没有,然后检查是否是版本问题,前后切换了ehcache-core的各个版本以及ehcache的各个版本均出现问题(ehcache的进行过get后再进行clear会报错)。
然后再误打误撞的检查源码时,发现com.jfinal.server.jetty.JettyServer中有这么几句:
// webApp.addSystemClass("sun."); // webApp.addSystemClass("com.sun."); webApp.getSystemClasspathPattern().add("sun.");// 支持 IDEA webApp.getSystemClasspathPattern().add("com.sun."); webApp.getSystemClasspathPattern().add("org.apache.");// 支持 jsp webApp.getSystemClasspathPattern().add("org.glassfish.");// 支持 jsp
上面的add("org.apache."),中的org.apache刚好是我使用的shiro的前缀。
于是乎我尝试自写server(基本上复制),并将上面的"org.apache."那一行去掉。
结果还真行了。
注:可能那一行有其他的作用,但是我作为测试用的jetty所以无所谓吧。
如果有其他路过的小伙伴有遇到相同的病症可以尝试一下。
这个问题前些天有人反馈过, jfinal 官方已经解决并提交了最新的代码,解决办法与你这个差不多,也是改这个地方,这里是最新代码:
https://gitee.com/jfinal/jetty-server/blob/master/src/main/java/com/jfinal/server/jetty/JettyServer.java
可以通过下面的办法用上最新版本:
git clone git@gitee.com:jfinal/jetty-server.git
cd jetty-server
mvn install
通过上面三行命令即可将最新版本安装到本地,然后再改一下原来的 jetty-server 版本为 2018.12-SNAPSHOT 即可