The spring container is used in the project to manage the business beans, and after receiving the request parameters from the foreground in the servlet, the calling business bean is always wrong.
The department code is as follows
[Java]View Plaincopy
- <span style="FONT-SIZE:18PX;" >private UserService userservice;
- Public UserService Getuserservice () {
- return userservice;
- }
- @Resource
- public void Setuserservice (UserService userservice) {
- this.userservice = UserService;
- }</span>
Use @resource annotation to inject, always error to say what
Name XXX is not bound in this Context
Let people depressed death, row wrong for a long time, and in action everything is normal, who knows why give me the next,
Here I find a way to solve the problem to share with you:
[Java]View Plaincopy
- Private UserService UserService;
- @Override
- public void init (ServletConfig servletconfig) throws servletexception {
- Super.init (ServletConfig);
- Webapplicationcontext Webapplicationcontext = Webapplicationcontextutils.getwebapplicationcontext ( Servletconfig.getservletcontext ());
- Userservice= (UserService) Webapplicationcontext.getbean ("Userserviceimpl");
- }
Servlet injects service business beans