java.lang.NoClassDefFoundError: ActionSupport异常和Action class not found异常
(2012-09-02 11:28:38) 标签: strutsactionsupporttomcat杂谈 | 分类: SSH |
出现以上异常通常有两种原因:
1、可能是没有加入xwork-2.1.2.jar这个包引起的,加入这个包即可,若加入这个包后还是没有解决问题。就看下面的第二种原因。
2、若加入了这个包,并且在配置struts项目的过程中出现以下两种情况:
(1)在部署好struts的项目,再启动Tomcat的Web服务器后,出现下面的Exception:
严重: Exception starting filter struts2
java.lang.NoClassDefFoundError: ActionSupport
at java.lang.ClassLoader.defineClass1(Native Method)
......
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: ActionSupport
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 37 more
(2)启动Tomcat的Web服务器,再重新部署struts项目时,出现以下Exception:
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/apache-tomcat-7.0.27/webapps/Registration_5/WEB-INF/classes/struts.xml:9:68
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteF
ilter.init(StrutsPrepareAndExecuteF
ilter.java:48)
......
org.apache.catalina.core.ContainerBase$ContainerBackgroundProce
ssor.run(ContainerBase.java:1526)
at java.lang.Thread.run(Thread.java:619)
Caused by: Action class [com.bjsxt.registeration.action] not found - action - file:/D:/apache-tomcat-7.0.27/webapps/Registration_5/WEB-INF/classes/struts.xml:9:68
...... com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 21 more
从上面的两个异常来看,一个是报ActionSupport没有被加载,一个是报一个Action类找不到,这就很明确的指出是因为Strut.xml文件的配置不对,里面的Action没有配置好其相应的Class路径。即
<struts>
<constant name="struts.devMode" value="true" />
<package name="registeration" extends="struts-default">
<action name="user" class="com.bjsxt.registeration.action">//此处没有深入到action包内
//的Action类
<result name="success">/registerSuccess.jsp</result>
<result name="fail">/registerFail.jsp</result>
</action>
</package>
</struts>
应该修正为:
<struts>
<constant name="struts.devMode" value="true" />
<package name="registeration" extends="struts-default">
<action name="user" class="com.bjsxt.registeration.action.UserAction">//加上Action类即可
<result name="success">/registerSuccess.jsp</result>
<result name="fail">/registerFail.jsp</result>
</action>
</package>
</struts>
(1)在部署好struts的项目,再启动Tomcat的Web服务器后,出现下面的Exception:
严重: Exception starting filter struts2
java.lang.NoClassDefFoundError: ActionSupport
Caused by: java.lang.ClassNotFoundException: ActionSupport
(2)启动Tomcat的Web服务器,再重新部署struts项目时,出现以下Exception:
严重: Exception starting filter struts2
Unable to load configuration. - action - file:/D:/apache-tomcat-7.0.27/webapps/Registration_5/WEB-INF/classes/struts.xml:9:68
......
Caused by: Action class [com.bjsxt.registeration.action] not found - action - file:/D:/apache-tomcat-7.0.27/webapps/Registration_5/WEB-INF/classes/struts.xml:9:68
......
从上面的两个异常来看,一个是报ActionSupport没有被加载,一个是报一个Action类找不到,这就很明确的指出是因为Strut.xml文件的配置不对,里面的Action没有配置好其相应的Class路径。即
<struts>
</struts>
应该修正为:
<struts>
</struts>