I came to know of this feature while writing code for @InterceptorRef example. I had to declare interceptor definitions in struts.xml file whereas I wanted to use the interceptor using annotations. On first attempt, It failed with following error:
Unable to load configuration. - [unknown location] at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70) at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446) at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490) Caused by: Unable to find interceptor class referenced by ref-name customStack - [unknown location] at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:63) at org.apache.struts2.convention.DefaultInterceptorMapBuilder.buildInterceptorList(DefaultInterceptorMapBuilder.java:95) at org.apache.struts2.convention.DefaultInterceptorMapBuilder.build(DefaultInterceptorMapBuilder.java:86) at org.apache.struts2.convention.DefaultInterceptorMapBuilder.build(DefaultInterceptorMapBuilder.java:64)
Reason:
By default the Convention plugin uses its own package convention-default which doesn’t contain your package defined in struts.xml. This means that the package where Convention is placing your actions, does not extend the package where the interceptor is defined.

Solution:
To change that you have two options :
@ParentPackage
annotation2) Define <constant name=”struts.convention.default.parent.package” value=”default”/ > in struts.xml
e.g.
<struts> <package name="default" namespace="/" extends="struts-default"> <interceptors> <interceptor name="demoCustomInterceptor" class="com.howtodoinjava.struts2.example.web.DemoCustomInterceptor" /> <interceptor-stack name="customStack"> <interceptor-ref name="demoCustomInterceptor"/> <interceptor-ref name="defaultStack" /> </interceptor-stack> </interceptors> </package> <constant name="struts.convention.result.path" value="/WEB-INF/jsp/" /> <constant name="struts.devMode" value="true" /> <constant name="struts.action.extension" value="action," /> <constant name="struts.custom.i18n.resources" value="test" /> <constant name="struts.convention.default.parent.package" value="default"/> </struts>
This will solve the issue.
Happy Learning !!
Comments