Solution that cannot inject business beans under SSH action __bean

Source: Internet
Author: User

Today, I tried to inject the bean automatically with the spring annotation, but I encountered a problem: it was not possible to automatically inject the bean with the @autowired annotation in the action, and the DAO Bean could be injected into the business bean, which was very strange, and the problem was solved by the lookup.

My action code is as follows:

@Result (name = "Success", location = "hello.jsp") public class Useraction extends Actionsupport {private static final Lon G Serialversionuid = 1L; @Autowired private Usermanager Usermanager; Public String Execute () {User user = new user (); User.setusername ("Cuihaiyang"); User.setpassword ("ABCD");////use @autowi Red cannot inject usermanager, but it can be obtained from the ApplicationContext, which means that the Usermanager bean has been automatically added to the spring container through the annotation @service string[] paths = { "Applicationcontext.xml"}; ApplicationContext context = new//Classpathxmlapplicationcontext (paths); Usermanager = (Usermanager) context.getbean ("Usermanager"); When the annotation @autowired is used, the Usermanager is null and the Usermanager.add (user) is not injected; return SUCCESS; } }

Later, seeing the replacement jar in http://blog.csdn.net/HMC20071120015/archive/2010/06/22/5686382.aspx solves the problem. I tried to replace the jar in my new project with the jar in the development project, and the result was injected successfully, which indicated that the configuration was not a problem with the jar pack. The next step is to find the problematic jar package with a little comparison, and finally find that Struts2-spring-plugin.jar is missing. I am not familiar with the SSH mechanism caused by low-level errors ah ....

Related Article

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.