您的位置:首页 > 编程语言 > Java开发

How to get a Spring bean in a Servlet filter?

2014-11-05 00:00 573 查看
Try:

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:

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

Also have a look at GenericFilterBean
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  spring
相关文章推荐