|字号订阅
文章声明
环境
Struts2-core-2.1.8.1错误解决方法
在分析Jetty源码的过程中,部署一个Servlet应用方便分析Jetty处理浏览器的请求。在启动Jetty后,应用初始化的过程中,出现了错误。完整的错误信息如下:15:24:58,015 ERROR [org.apache.struts2.dispatcher.Dispatcher] Dispatcher initialization failed Unable to load configuration. - bean - jar:file:/D:/Study/servicemn/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:59:150 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418) at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51) at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:662) at org.mortbay.jetty.servlet.Context.startContext(Context.java:140) at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250) at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517) at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152) at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) at org.mortbay.jetty.Server.doStart(Server.java:224) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985) 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.mortbay.start.Main.invokeMain(Main.java:194) at org.mortbay.start.Main.start(Main.java:534) at org.mortbay.start.Main.start(Main.java:441) at org.mortbay.start.Main.main(Main.java:119) Caused by: Unable to load bean: type:org.apache.struts2.components.template.TemplateEngine class:org.apache.struts2.components.template.JspTemplateEngine - bean - jar:file:/D:/Study/servicemn/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:59:150 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:221) at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101) at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:169) at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55) ... 29 more Caused by: java.lang.NoClassDefFoundError: javax/servlet/jsp/JspWriter at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) at java.lang.Class.getDeclaredConstructors(Class.java:1836) at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:211) ... 32 more Caused by: java.lang.ClassNotFoundException: javax.servlet.jsp.JspWriter at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:392) at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:363) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 36 more
原因/解决方法:
1、查看 struts2-core-2.1.8.1.jar 中的struts-default.xml的59行,其内容如下:
<bean type="org.apache.struts2.components.template.TemplateEngine" name="jsp" class="org.apache.struts2.components.template.JspTemplateEngine" />
Caused by: java.lang.ClassNotFoundException: javax.servlet.jsp.JspWriter 结合上述两点,断定问题是缺少了 jsp-api 类库。给Jetty增加其所需的jsp-api类库,如下所示: 问题解决。 如果 Struts2 报 Unable to load configguration. - bean 的错误,肯定是因为缺少所需的类库的引起的,可以根据错误信息的提示增加所需的类库即可。
<正文结束>
转者补充:
我遇到的问题类似,是缺少freemarker.jar,但我在WEB-INF/lib下是有个freemarker.jar的,我去freemarker的官网下载了个新的来替换,结果错误消失了。