读书人

spring流入servlet

发布时间: 2012-07-18 12:05:41 作者: rapoo

spring注入servlet

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

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

?

这样就把xxxInterfaceImpl注入进来了。

读书人网 >软件架构设计

热点推荐