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 ....