Reputation: 31
Recently I did try to configure [Struts 2 annotation] with [XML config] together, although the XML always overrides the annotations config. It is possible to use them together? Or no way?
Upvotes: 1
Views: 509
Reputation: 41
You don't need to add anything to the web.xml if you meet the following:
The convention plugin searches for packages with names: struts, struts2, action, actions and then searches all their subpackages for classes that implement Action
(or extends ActionSupport
which implements Action
), and classes whose names end with "Action".
See more:
https://struts.apache.org/plugins/convention/#introduction
It will find these classes automatically and search for annotations inside them.
Upvotes: 0
Reputation: 162
You can use both. For using annotation you need the Convention Plugin. And you need to mention in web.xml that you are using annotations like this
<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>package</param-value>
</init-param>
</filter>
This official struts site is a good place to start.
Upvotes: 2