Question

I am getting this issue when using Annotations in my Struts2 code.

My Annotated Action class seems something like this which is using interceptors, and my architecture is based on Spring 3, Struts 2, and using Struts2 Convention Plugin

@InterceptorRefs({  
    @InterceptorRef("mylogging")  
}) 
public class LoginAction  implements ModelDriven{
    User user = new User();
    List<User> users = new ArrayList<User>();
    UserBo userBo;
    @Action(value="/login",results={@Result(name="success",type="chain",location="/jsp/successPage.jsp"),
            @Result(name="login",type="chain",location="/jsp/userLogin.jsp")})
    public String execute() {
        if(user.getUserScreenName()==null)
            return "login";
        System.out.println(userBo.verifyUser(user));
        return "success";
    }

I am also trying to enclose the details of my deployment descriptor

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
        <init-param> <param-name>config</param-name> <param-value>struts-default.xml,struts-plugin.xml,struts.xml
</param-value>
            </init-param>
      </filter>


      <filter-mapping>

        <filter-name>struts2</filter-name>
        <url-pattern>*.action</url-pattern>
      </filter-mapping>
      <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/resources/config/SpringBeans.xml</param-value>
    </context-param>

       <listener>
        <listener-class>
          org.springframework.web.context.ContextLoaderListener
        </listener-class>

      </listener>

I have defined my interceptor in struts.xml which I am just using for defining interceptors and result types

   <struts>
    <constant name="struts.devMode" value="false" />
     <constant name="struts.objectFactory" value="spring" />
     <constant name="struts.convention.package.locators.basePackage" value="com.abc.lab"/>
     <constant name="struts.convention.action.checkImplementsAction" value="false"/>
      <constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/> <package name="default" extends="struts-default" namespace="/">
     <interceptors>
            <interceptor name="mylogging" 
                class="com.abc.lab.interceptor.LoggingInterceptor">
            </interceptor>
            <interceptor-stack name="loggingStack">
                <interceptor-ref name="mylogging" />

                <interceptor-ref name="defaultStack" />    
            </interceptor-stack>
        </interceptors> </package> </struts>

I have also tried with devMode true or false but it wasn't helpful.

My directory structure is

+--LmsWar/
|  +--pom.xml
|  +--src/
|  |  +--com/
|  |  |  +--abc/
|  |  |  |  +--lab/
|  |  |  |  |  +--actions/
|  |  |  |  |  |  +--HomeAction.java
|  |  |  |  |  |  +--LoginAction.java
|  |  |  |  |  +--bo/
|  |  |  |  |  |  +--impl/
|  |  |  |  |  |  |  +--UserBoImpl.java
|  |  |  |  |  |  +--UserBo.java
|  |  |  |  |  +--dao/
|  |  |  |  |  |  +--impl/
|  |  |  |  |  |  |  +--UserDAOImpl.java
|  |  |  |  |  |  +--UserDAO.java
|  |  |  |  |  +--filter/
|  |  |  |  |  +--interceptor/
|  |  |  |  |  |  +--LoggingInterceptor.java
|  |  |  |  |  +--listener/
|  |  |  |  |  +--model/
|  |  +--resources/
|  |  |  +--com/
|  |  |  |  +--abc/
|  |  |  |  |  +--lab/
|  |  |  |  |  |  +--spring/
|  |  |  |  |  |  |  +--UserBean.xml
|  |  |  +--config/
|  |  |  |  +--database/
|  |  |  |  |  +--properties/
|  |  |  |  |  |  +--database.properties
|  |  |  |  +--spring/
|  |  |  |  |  +--DataSource.xml
|  |  |  |  |  +--HibernateSessionFactory.xml
|  |  |  |  +--SpringBeans.xml
|  |  +--struts.properties
|  |  +--struts.xml
|  +--WebRoot/
|  |  +--jsp/
|  |  |  +--common/
|  |  |  +--layout/
|  |  +--WEB-INF/
|  |  |  +--classes/
|  |  |  +--lib/
|  |  |  +--tiles.xml
|  |  |  +--web.xml

EDIT:

After getting into more details and add detailed loggings I got one more thing in my logs.

2013-07-23 16:40:01,578 ERROR com.opensymphony.xwork2.util.finder.ClassFinder.error:38 - Unable to read class [com.abc.lab.actions.LoginAction] java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)V

And it's only one exception which I have mentioned here while it's giving the same exception with each action class available in my application.

Was it helpful?

Solution

Your configuration is wrong. You should

  • extend struts-default in your package, and
  • add your interceptor to the default stack or to some other custom stack; right now, your whole stack is composed by only ONE interceptor, your.

Working configuration:

<package name="default" extends="struts-default">
     <interceptors>
            <interceptor name="mylogging" 
                class="com.abc.lab.interceptor.LoggingInterceptor">
            </interceptor>
            <interceptor-stack name="loggingStack">
                <interceptor-ref name="mylogging" />

                <interceptor-ref name="defaultStack" />    
            </interceptor-stack>
        </interceptors>
</package>

You may want to include the namespace too in your package declaration, like

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

And if you want to use Spring DI to inject beans in your Actions, you need to put the following setting in struts.xml:

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

And please, do not use chain result: it is discouraged in the official documentation. It is highly likely that you have a better way to do what you want to achieve, for example with redirectAction result instead of chain result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top