Autowiring in servlet Autowiring in servlet spring spring

Autowiring in servlet


I followed the solution in the following link, and it works fine:Access Spring beans from a servlet in JBoss

public class MyServlet extends HttpServlet {  @Autowired  private MyService myService;  public void init(ServletConfig config) {    super.init(config);    SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,      config.getServletContext());  }}


Remove the @Configurable annotation from your servlet and add:

SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext (this);

at the first line of your init() method.