首页 > 编程语言 > 详细

How to get a Spring bean in a Servlet filter?

时间:2014-11-05 13:13:03      阅读:309      评论:0      收藏:0      [点我收藏+]

Try:

 

  1. UsersConnectionRepository bean =   (UsersConnectionRepository)WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()).getBean("usersConnectionRepository");  

 

Where usersConnectionRepository is a name/id of your bean in the application context. Or even better:

 

  1. UsersConnectionRepository bean = WebApplicationContextUtils.getRequiredWebApplicationContext(filterConfig.getServletContext()).getBean(UsersConnectionRepository.class);  


Also have a look at GenericFilterBean


How to get a Spring bean in a Servlet filter?

原文:http://my.oschina.net/sunpr/blog/340966

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!