本篇对 Web 开发中,项目部署后、开启 Tomcat 服务器 Console 控制台报错 java.lang.NoClassDefFoundError: ognl/PropertyAccessor 进行分析,并将解决方法记录如下:
一、异常描述:
1 java.lang.NoClassDefFoundError: ognl/PropertyAccessor 2 at 3 com.opensymphony.xwork2.config.impl.DefaultConfiguration.createBootstrapContainer 4 (DefaultConfiguration.java:318) 5 at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer 6 (DefaultConfiguration.java:221) 7 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration 8 (ConfigurationManager.java:67) 9 at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration 10 (Dispatcher.java:446) 11 at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490) 12 at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher 13 (InitOperations.java:74) 14 at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init 15 (StrutsPrepareAndExecuteFilter.java:57) 16 at org.apache.catalina.core.ApplicationFilterConfig.initFilter 17 (ApplicationFilterConfig.java:279) 18 at org.apache.catalina.core.ApplicationFilterConfig.getFilter 19 (ApplicationFilterConfig.java:260) 20 at org.apache.catalina.core.ApplicationFilterConfig.<init> 21 (ApplicationFilterConfig.java:105) 22 at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4908) 23 at org.apache.catalina.core.StandardContext.startInternal 24 (StandardContext.java:5602) 25 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) 26 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899) 27 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875) 28 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) 29 at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260) 30 at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002) 31 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 32 at java.util.concurrent.FutureTask.run(FutureTask.java:266) 33 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 34 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 35 at java.lang.Thread.run(Thread.java:745) 36 Caused by: java.lang.ClassNotFoundException: ognl.PropertyAccessor 37 at org.apache.catalina.loader.WebappClassLoaderBase.loadClass 38 (WebappClassLoaderBase.java:1858) 39 at org.apache.catalina.loader.WebappClassLoaderBase.loadClass 40 (WebappClassLoaderBase.java:1701) 41 ... 23 more
二、错误分析:缺少 ognl 的 jar 包,无法找到类 ognl/PropertyAccessor。
三、解决方法:ognl/PropertyAccessor 的 class 字节码文件在 ognl 的 jar 包下,将 ognl 的 jar 包导入即可。