当前位置: 代码迷 >> Java Web开发 >> Struts2.0和sping3.0结合 诡异错误Unable to instantiate Action
  详细解决方案

Struts2.0和sping3.0结合 诡异错误Unable to instantiate Action

热度:7938   发布时间:2013-02-25 21:12:06.0
Struts2.0和sping3.0结合 诡异异常Unable to instantiate Action
本人在整合一个小项目,struts2.2.3版本和sping3.0结合 在登陆页面点击登陆的时候(action路径为:login.action)报了一个很诡异的异常,查了很多资料无人解读,希望有人帮忙解决一下:
exception

Unable to instantiate Action, loginAction, defined for 'login' in namespace '/'loginAction
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:318)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:399)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:198)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)

root cause

java.lang.ClassNotFoundException: loginAction
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:157)
com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:107)
com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:223)
。。。。。。。。。。。

在只有struts的时候项目运行是没有问题的 但是加入了sping之后就遇到了顶上的这个问题。浪费了很长时间。下面是我的配置文件:

struts.xml:

<constant name="struts.objectFactory" value="spring" />

<package name="default" extends="struts-default" >
<interceptors>
<!-- 定义AuthenticationInterceptor拦截器 -->
<interceptor name="auth" 
class="interceptor.AuthenticationInterceptor"/>

<!-- 定义我们自己的拦截器栈,在Action的配置中,可以直接引用这个拦截器栈 -->
<interceptor-stack name="securityStack">

<interceptor-ref name="auth"/>
<interceptor-ref name="defaultStack">
<param name="workflow.excludeMethods">default</param>
<param name="validation.excludeMethods">default</param>
</interceptor-ref>
 
</interceptor-stack>
</interceptors>

<default-interceptor-ref name="securityStack"></default-interceptor-ref>

<global-results >
<result name="login">/index.jsp</result>
</global-results>

<action name="admin" class="action.AdminAction">
<result name="addSuccess">/main.jsp</result>
<result name="input">/newOperator.jsp</result>
</action>
 
 
 
<action name="login" class="loginAction">
<result name="success">/main.jsp</result>
<result name="login">/index.jsp</result>
</action>
   
  </package>

applicationContext.xml:

  <bean id="adminService" class="business.AdminService" scope="prototype"/>

<bean id="loginAction" class="action.LoginAction"
scope="prototype">
<property name="service" ref="adminService" />
</bean>

希望各位大牛给我指点迷津!!!!!

------解决方案--------------------------------------------------------
<action name="login" class="loginAction">
  相关解决方案