Package Com.orm.servlet;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import java.util.List;
Import Javax.servlet.ServletConfig;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Org.springframework.context.ApplicationContext;
Import org.springframework.web.context.support.WebApplicationContextUtils;
Public class testservlet extends httpservlet {
Private Static Final Longserialversionuid = 1L;
Private Iloginservice Loginservice;
Private ApplicationContext ApplicationContext;
public void init ( Servletconfig config) throws servletexception {
Super . init (config);
ApplicationContext = Webapplicationcontextutils.getrequiredwebapplicationcontext (this. Getservletcontext ());
Loginservice= (iloginservice) Applicationcontext.getbean ("loginservice") ;
}
}
The only difference is that the bean needs to be manually injected into the init () method, as is the case with the normal development process.
Spring+servlet consolidation (How to inject attributes into a servlet)