java - Spring injection Into Servlet - Stack Overflow I created a parent abstract servlet class that...

Please Visit: http://ift.tt/1ajReyV



java - Spring injection Into Servlet - Stack Overflow



I created a parent abstract servlet class that retrieves the Spring context, gets and autowiring-capable factory and uses that factory to autowire the servlet instances (the subclasess, actually). I also store the factory as an instance variable in case the subclasses need it.

So the parent abstract servlet looks like this:

public abstract class AbstractServlet extends HttpServlet {

protected AutowireCapableBeanFactory ctx;

@Override

public void init() throws ServletException {

super.init();

ctx = ((ApplicationContext) getServletContext().getAttribute(

"applicationContext")).getAutowireCapableBeanFactory();

//The following line does the magic

ctx.autowireBean(this);

}

}http://ift.tt/1l0IrXT

http://ift.tt/1g60L5Z



java - Spring injection Into Servlet - Stack Overflow







from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1l0IrXX

via LifeLong Community

No comments:

Post a Comment