1. 程式人生 > >struts2+spring Unable to instantiate Action

struts2+spring Unable to instantiate Action

錯誤程式碼:HTTP Status 500 - Unable to instantiate Action, myIndexAction1, defined for 'Index' in namespace '/'Cannot find class [action.IndexAction] for bean with name 'myIndexAction1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: action.IndexAction

type Exception report

message Unable to instantiate Action, myIndexAction1, defined for 'Index' in namespace '/'Cannot find class [action.IndexAction] for bean with name 'myIndexAction1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: action.IndexAction

description The server encountered an internal error that prevented it from fulfilling this request.

exception

Unable to instantiate Action, myIndexAction1,  defined for 'Index' in namespace '/'Cannot find class [action.IndexAction] for bean with name 'myIndexAction1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: action.IndexAction - action - file:/G:/SoftWare/apache-tomcat-7.0.63-windows-x64/apache-tomcat-7.0.63/webapps/ssh_demo/WEB-INF/classes/struts.xml:10:72
	com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:317)
	com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:398)
	com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
	.....

root cause

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [action.IndexAction] for bean with name 'myIndexAction1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: action.IndexAction
	org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1357)
	......

root cause

java.lang.ClassNotFoundException: action.IndexAction
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1722)
	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1573)
	org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
	org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:394)
	org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1402)
	......

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.63 logs.

1.首先要看看自己的配置是否正確:這裡有一個帖子可以簡單看一下 http://www.cnblogs.com/S-E-P/archive/2012/01/18/2325253.html 如果是配置問題那麼更改之後就能正常訪問。在配置完全正確,jar包沒有缺少的情況下。看下文。

2.我遇到的問題是,配置完全正確,偶爾也能正常載入,但是大部分時候就報錯(如上文所示)搞了很久之後開始想,不能載入類。這個類存在嗎?於是便去tomcat的該專案目錄的classes目錄下檢視,發現並沒有class檔案,看到這裡,又想到,可能是沒有編譯成功,於是更專案的jre ,javacomplier版本,tomcat 的jdk為同一版本,這才正常執行。

3.之前也遇到過,但是不知道如何解決,這次隨著時間的積累,有自己的推理,知道了為什麼。很激勵自己,加油!