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
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
相关文章推荐
- How to get session information in Spring MVC 3
- 在Bean(java类)中如何取到jspx中Bindings的数据?How to get the ADF BindingContainer in a managed bean?
- How to inject value into bean properties in Spring
- Spring管理filter和servlet ( FilterToBeanProxy/DelegatingFilterProxy)
- How to get the HttpServletRequest in Struts 2
- How To Get Properties Data in Spring
- how to get url and hostname and url text in one page
- How to get the size of file in C++ - 在C++中如何获取文件的大小
- How to get request_id of previous request in a request set?
- How to get and set the system socket buffer in AIX?
- 【摘自Devx】How to pass parameters to Thread in Windows Forms -- and get results back
- Spring异常:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本
- How to get a top sales glasses online in Hawaii
- 异常:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletCo
- How to get persons who have responsed to a survey in MOSS?
- How to invoke the method of managed bean and render view in JSF when we are outside the lifecycle of JSF
- How to use GET and POST methods in HTTP from a MIDlet
- (iAS10g)Howtousereports/rwservlettogetreportserverinformation
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContex