Servlet自动注入service的方法
注入方法::在Servlet的init方法中增加以下代码:
init(ServletConfig config) throws ServletException {
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
}
并且在注入的变量增加@Autowired:
或者
init(ServletConfig config) throws ServletException {
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
serviceI=(serviceI) webApplicationContext.getBean("serviceImpl");
}
注入方法::在Servlet的init方法中增加以下代码:
init(ServletConfig config) throws ServletException {
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
}
并且在注入的变量增加@Autowired:
或者
init(ServletConfig config) throws ServletException {
WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
serviceI=(serviceI) webApplicationContext.getBean("serviceImpl");
}