在servlet中得到spring注入的bean

public void init(ServletConfig servletConfig) throws ServletException {
      ServletContext servletContext = servletConfig.getServletContext();
      WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
      YOUR_BEAN = (YOUR_BEAN) webApplicationContext.getBean("your_bean_name");
 }

原文地址:https://www.cnblogs.com/jiaoyiping/p/3070314.html