0

错误是:

type Exception report

message 

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

exception 

Unable to instantiate Action, addUserAction,  defined for 'addUser' in namespace '/'addUserAction
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:307)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
    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:47)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)


root cause 

java.lang.ClassNotFoundException: addUserAction
    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:146)
    com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:96)
    com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:212)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:132)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:139)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:109)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:288)
    com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:388)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:187)
    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:47)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:478)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

因此,它显示容器找不到 addUserAction。但是,请查看我的 struts.xml 和 applicationContext.xml:

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.objectFactory" value="spring"/>
<include file="struts-default.xml"></include>
<package name="default" extends="struts-default">
 <action name="addUser" class="addUserAction">
    <result name="success">/add_success.jsp</result>
    <result name="error">/add_error.jsp</result>
  </action>
</package>
</struts> 

applicationContext.xml 的一部分:

<bean id="userService" class="com.rainbow.service.impl.UserServiceImpl">
        <property name="userDAO" ref="userDAO"></property>
    </bean>
<bean id="addUserAction" class="com.rainbow.action.AddUserAction" scope="prototype">
        <property name="userService" ref="userService"></property>
    </bean>  

很明显 addUserAcion 是“com.rainbow.action.AddUserAction”,所以我找不到原因,希望有人能帮助我,非常感谢!

网页.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <listener>
  <listener-class>
    org.springframework.web.context.ContextLoaderListener
  </listener-class>
  </listener>
  <context-param>  
      <param-name>contextConfigLocation</param-name>  
      <param-value>classpath*:applicationContext.xml</param-value>  
  </context-param>
  </web-app>
4

1 回答 1

0

你在类路径中有所有必要的 jar 文件吗?你有struts2-spring-plugin jar 文件吗?

于 2012-05-02T09:52:03.627 回答