Struts 2 considerations for integrating spring (2)

Source: Internet
Author: User


There is a strus in the struts2_spring_plugin.xml configuration file. objectFactory. spring. the default value of the autoWire attribute is name, which means you do not want to load it, it will find a bean with the id as name to load it to you (this plug-in automatically injects the Action attributes when generating the action, by default, it is injected by name ), for example:

@ Resource (name = "userManager ")
Public void setUm (UserManager um ){
This. um = um;
}

If you do not add the previous @ Resource (name = "userManager"), it will automatically find you a bean with an id of um for injection.


Another point is that if a bean has been automatically matched by name, no matter what the name configuration of @ component (name = "xxxx") will be found again.


Solve the problem: the attribute name should not be the same as the id of other irrelevant beans. For example, there is a User (SetUser () in UserAction ()) this UserAction should not be called @ Resource (name = "user"). You can change it

@ Resource (name = "useraction"), that is, the id of the Action should not be the same as the attribute name in it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.