javaxmlstruts2annotationsstruts2-convention-plugin

Struts2 Annotated or XML based ? which is more easier to manage and uncomplicated?


Which is the easier and organized way to use Struts2 ? With Annotations or with XML files ?

If with annotations, then with which kind of annotations? With struts-convention-plugin you can even avoid completely writing conventions i.e@results or @action.

What benefits will annotations give over not writing them ?


Solution

  • I've always used XML, and I've started recently using Convention.

    I would now say that you can still use XML, but it would be better to use Annotations.

    The facts in support to this are that, with Convention plugin;

    1. less code is needed: since Convention plugin will scan some packages looking for Actions, you don't need to declare any action anymore. The same is applied to method name, result declaration, and so on: you will specify only things that differ from the standard behavior, while with XML you will have to write "the obvious" each time;
    2. the knowledge is decentralized (or distributed): the configuration is now in the place it is meant to be; if you are inside an Action, you don't need to open the struts.xml configuration file, find the action element (among many others) to discover how it is configured; you can simply look at the Annotations inside the class to understand immediately how it works. The same is applied to Validation (inside the class and not in the actionName-validation.xml file;

    This will help you having more granularity, a cleaner code, smaller files and almost no configuration.