当web.xml与applicationContext.xml配置没有错误,servlet无法读取到spring中定义的service对象
servlet无法获取到spring中定义的service对象
当web.xml与applicationContext.xml配置没有错误,servlet无法获取到spring中注入的service对象
spring默认不支持servlet
利用servlet的init方法,在初始化过程中注入spring
public void init() throws ServletException {
//spring容器默认不支持servlet,需要在初始化过程中注入spring
ServletContext cont = getServletContext();
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, cont);
super.init();
}
然后servlet就可以通过spring注解来获得service对象了