开发者

Unable to instantiate Action, signupFormAction, defined for 'signupForm' in namespace '/'signupFormAction. ClassNotFoundException: signupFormAction

Been trying to setup a Struts2 + Sprint + Hibernate basic framework and was working on creating a sample application. Everything configured and the stack doesnt through any error/exception while starting tomcat. Even when I run the action it doesnt throw any Exception, but on the browser it throws the following stack

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)

My 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>

My 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>

My 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>

My Action Class

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(ownerLastN开发者_StackOverflow社区ame);
        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;
    }

}


I made a trivial mistake which costed me hours of pain. Silly me the problem was that my class name in struts.xml and id in register.xml were not matching and hence the issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜