servlet中如何实现通过Spring实现对象的注入

@WebServlet("/BaseServlet")
public class BaseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public void init() throws ServletException {
super.init();
WebApplicationContextUtils.getWebApplicationContext(getServletContext()).getAutowireCapableBeanFactory().autowireBean(this);
}

}

需要注入的servlet可以通过继承BaseServlet 即可实现。

原文地址:https://www.cnblogs.com/Onedayzk/p/7344239.html