I have been trying to use interceptor with annotation in struts2 to handle my request and responses so that I can perform some pre and post actions.
But, I have used struts 2 with convention plugin initially which I can't really change. My framework also include spring in it.
But, now problem is whenever I have been trying to use interceptor as annotation in action it gives me following exception at the start of application.
SEVERE: Exception starting filter struts2
Unable to load configuration. - [unknown location]
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:483)
....
Caused by: Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
.....
Caused by: Unable to find interceptor class referenced by ref-name mylogging - [unknown location]
My code structure is quite simple:
Action class seems like:
@InterceptorRefs({
@InterceptorRef("mylogging")
})
public class LoginAction implements ModelDriven{
.....
@Action(value="/login",results={@Result(name="success",location="/jsp/successPage.jsp"),
@Result(name="login",location="/jsp/userLogin.jsp")})
public String execute() {
....
Struts.xml:
<struts>
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<package name="default" namespace="" extends="struts-default">
<interceptors>
<interceptor name="mylogging"
class="com.lab.interceptor.LoggingInterceptor">
</interceptor>
<interceptor-stack name="loggingStack">
<interceptor-ref name="mylogging" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
</package>
</struts>
My deployment descriptor body (web.xml):
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.lab.actions</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>
Now hopefully it will help to figure out why it's throwing that exception, because i don't think I need to remove implementation of ModelDriven from my action.
Thanks in Advance
By default the Convention plugin uses its own package convention-default
which doesn't contain your package defined in struts.xml. To change that you have two options, both described in the docs [1]:
@ParentPackage
annotation<constant name="struts.convention.default.parent.package" value="default"/>
in struts.xml