Using struts.xml with convention plugin
- by David Alt
This seems like it should be easy to do, but I just can make it work. I'm hooked on the convention plugin in Struts 2.1. However, I need to define some package-level configuration such as a new interceptor stack and exception mappings. I'd like to use the struts.xml file for this, but I can't get the convention-based packages matched to the struts.xml packages. My struts.xml looks like:
<struts>
<constant name="struts.convention.default.parent.package" value="default"/>
<package name="default" extends="struts-default">
</package>
<package name="root" namespace="/" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
</package>
<package name="my.package.actions.myaccount" namespace="/myaccount" extends="struts-default">
<interceptors>
<interceptor name="authenticationInterceptor" class="my.package.interceptors.AuthenticationInterceptor"/>
<interceptor-stack name="secureStack">
<interceptor-ref name="authenticationInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureStack"/>
</package>
</struts>
I have my interceptor in:
/src/my/package/interceptors
and my actions in:
/src/my/package/actions/myaccount