1. annotation与struts.xml互斥,一定要删除xml文件后再用annotation.
2. annotation 最好将相应的action放入action包中,这样convention可以找到,否则可能会找不到。
3.
These packages are located by the Convention plugin using a search methodology. First the Convention plugin finds packages named struts , struts2 , action or actions . Any packages that match those names are considered the root packages for the Convention plugin. Next, the plugin looks at all of the classes in those packages as well as sub-packages and determines if the classes implement com.opensymphony.xwork2.Action or if their name ends with Action (i.e. FooAction). Here's an example of a few classes that the Convention plugin will find:
com.example.actions.MainAction
com.example.actions.products.Display (implements
com.opensymphony.xwork2.Action)
com.example.struts.company.details.ShowCompanyDetailsAction
Each of the action classes that the plugin finds will be configured to respond to specific URLs. The URL is based on the package name that the class is defined in and the class name itself. First the plugin determines the namespace of the URL using the package names between the root package and the package the class is defined in. For our examples above, the namespaces would be:
com.example.actions.MainAction -> /
com.example.actions.products.Display -> /products
com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details
Next, the plugin determines the URL of the resource using the class name. It first removes the word Action from the end of the class name and then converts camel case names to dashes. In our example the full URLs would be:
com.example.actions.MainAction -> /main
com.example.actions.products.Display -> /products/display
com.example.struts.company.details.ShowCompanyDetailsAction -> /company/details/show-company-details