javastruts2struts2-json-pluginstruts2-interceptors

Unable to find interceptor class referenced by ref-name jsonValidationWorkflowStack


In my Struts2 application I have the following action in struts.xml

<action name="submitRecruitmentProcess" method="submitRecruitmentProcess"
            class="com.erp.people.action.RecruitementProcessManagementAction">
            <result name="success">jsp/process/processlist.jsp</result>         
            <interceptor-ref name="jsonValidationWorkflowStack"></interceptor-ref>
            <result name="input" type="json">
                <param name="ignoreHierarchy">false</param>
                <param name="includeProperties">actionErrors\[\d+\], fieldErrors\..+$,
                    actionMessages\[\d+\]</param>
            </result>    
        </action>

I am extending the json-default in ma struts.xml file and also using struts-json pluggin in my classpath. But on running the application I am getting an error like the following

Unable to find interceptor class referenced by ref-name jsonValidationWorkflowStack

Any idea on what is going wrong,any help is appreciated.

I have followed this link

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Struts2</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>jsp/login/login.jsp</welcome-file>
    </welcome-file-list>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <context-param>
    <param-name>
      org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
    </param-name>
    <param-value>/WEB-INF/tiles.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
  </listener>

</web-app>

Solution

  • The error says that you have not placed the struts2 json plugin jar file in classpath (i.e in WEB-INF/lib). Get the struts2-json-plugin-2.3.20.jar and put it in classpath to fix the issue. If you have downloaded struts2 Jars then this Jar file can be seen as part of the downloaded package.

    While checking the link you have provided I have observed few issues if you want to use Struts2-2.3.20.

    1) The DOCTYPE declaration in struts.xml is not correct. It should be like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
       "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
       "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>
        <package name="default" extends="json-default">
            <action name="login" class="com.examples.action.LoginAction">
                <interceptor-ref name="jsonValidationWorkflowStack"></interceptor-ref>
                <result name="input" type="json">
                    <param name="ignoreHierarchy">false</param>
                    <param name="includeProperties">actionErrors\[\d+\], fieldErrors\..+$,
                        actionMessages\[\d+\]</param>
                </result>
            </action>
        </package>
    </struts>
    

    I just named the login class with different package for testing.

    Also the DOCTYPE declaration for validation.xml file is not proper, it should be like this:

    <?xml version="1.0" encoding="UTF-8"?>   
    
    <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
            "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
    

    Now coming to plugins, if you do not have the JSON plugin in classpath then you will get runtime exception as:

    Caused by: Parent package is not defined: json-default
    

    To fix this add struts2-json-plugin-2.3.20 in WEB-INF/lib of your application so it will be in classpath.

    Now as the JSP pages are using JQuery tags you have to place the struts2-jquery-plugin-2.5.3.jar in classpath.

    I have tested it with Struts2-2.3.20 version, correct your code and see if that fixes the issue.