`
g21121
  • 浏览: 698051 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring注入servlet

 
阅读更多

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

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

 

这样就把xxxInterfaceImpl注入进来了。

1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics