无法实例化为名称空间'/'signupFormAction中的'signupForm'定义的Action,signupFormAction。 ClassNotFoundException:signupFormAction

时间:2011-03-03 17:54:02

标签: instantiation

尝试设置Struts2 + Sprint + Hibernate基本框架,并正在努力创建示例应用程序。配置的所有内容和堆栈在启动tomcat时都没有通过任何错误/异常。即使我运行该操作它也不会抛出任何异常,但在浏览器上它会抛出以下堆栈

Unable to instantiate Action, signupFormAction,  defined for 'signupForm' in namespace '/'signupFormAction
    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:475)
    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: signupFormAction
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    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)
    com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:143)
    com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:150)
    com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:120)
    com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:299)
    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:475)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)

我的struts.xml

<struts>
<!--    <constant name="struts.enable.DynamicMethodInvocation" value="false" />-->
    <constant name="struts.devMode" value="false" />

    <constant name="struts.custom.i18n.resources" value="ApplicationResources" />

    <package name="default" extends="struts-default" namespace="/">

        <action name="login" class="loginAction">
            <result name="success">welcome.jsp</result>
            <result name="error">login.jsp</result>

        </action>
        <action name="signup" class="registerAction" method="add">
            <result name="success">welcome.jsp</result>
            <result name="error">login.jsp</result>

        </action>
        <action name="signupForm" class="signupFormAction">
            <result name="input">registerForm.jsp</result>
            <result name="error">login.jsp</result>
        </action>

    </package>
</struts>

我的SpringBeans.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    <!-- Database Configuration -->
    <import resource="config/spring/DataSource.xml" />
    <import resource="config/spring/HibernateSessionFactory.xml" />


    <!-- Beans Declaration -->
    <import resource="com/srisris/khiraya/spring/register.xml" />
    <import resource="com/srisris/khiraya/spring/login.xml" />

</beans>

我的register.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<!--    <bean id="ownerService" class="com.srisris.khiraya.service.OwnerServiceImpl">-->
<!--         <property name="ownerDAO" ref="ownerDAO" />-->
<!--    </bean>-->

    <bean id="signupForm" class="com.srisris.khiraya.action.RegisterAction"/>

<!--    <bean id="registerAction" class="com.srisris.khiraya.action.RegisterAction">-->
<!--        <property name="ownerService" ref="ownerService" /> -->
<!--    </bean>-->
<!--    <bean id="ownerDAO" class="com.srisris.khiraya.dao.OwnerDAOImpl" >-->
<!--        <property name="sessionFactory" ref="sessionFactory" />-->
<!--    </bean>-->
</beans>

我的动作类

package com.srisris.khiraya.action;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.srisris.khiraya.dao.hibernate.Owner;
import com.srisris.khiraya.service.OwnerService;

@SuppressWarnings("rawtypes")
public class RegisterAction extends ActionSupport implements ModelDriven{
    private static final long serialVersionUID = 6521996078347478542L;

    private String ownerFirstName;
    private String ownerLastName;
    private String username;
    private String password;
    private String ownerPhone;
    private String ownerEmail;

    private OwnerService ownerService;
    Owner owner = new Owner();


    public void setOwnerService(OwnerService ownerService) {
        this.ownerService = ownerService;
    }

    public String add() {
            owner.setOwnerFirstName(ownerFirstName);
        owner.setOwnerLastName(ownerLastName);
        owner.setOwnerPassword(password);
        owner.setOwnerPhone(ownerPhone);
        owner.setOwnerEmail(ownerEmail);
        ownerService.save(owner);
        return SUCCESS;
    }

    public String execute() {
        return INPUT;
    }

    public String getOwnerFirstName() {
        return ownerFirstName;
    }

    public void setOwnerFirstName(String ownerFirstName) {
        this.ownerFirstName = ownerFirstName;
    }

    public String getOwnerLastName() {
        return ownerLastName;
    }

    public void setOwnerLastName(String ownerLastName) {
        this.ownerLastName = ownerLastName;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getOwnerPhone() {
        return ownerPhone;
    }

    public void setOwnerPhone(String ownerPhone) {
        this.ownerPhone = ownerPhone;
    }

    public String getOwnerEmail() {
        return ownerEmail;
    }

    public void setOwnerEmail(String ownerEmail) {
        this.ownerEmail = ownerEmail;
    }

    public Object getModel() {
        return owner;
    }

}

1 个答案:

答案 0 :(得分:2)

我犯了一个微不足道的错误,花了我几个小时的痛苦。愚蠢我的问题是我的struts.xml中的类名和register.xml中的id不匹配,因此问题。