spring注入servlet

传统的配置方法是无法将bean或属性直接注入到servlet中的,配置代理servlet亦比较麻烦,这里其实有比较简单的方法,其实就是在servlet的init()方法中加入要注入的内容:

ServletContext application = getServletContext();
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(application);// 获取spring的context
xxxInterface= (xxxInterfaceImpl) wac.getBean("xxxInterface");

这样就把xxxInterfaceImpl注入进来了。

猜你喜欢

转载自286.iteye.com/blog/1446327
今日推荐