在filter中的init方法中写:
@Override
public void init(FilterConfig filterConfig) throws ServletException {
ServletContext servletContext = filterConfig.getServletContext();
ApplicationContext Context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
user = (User) Context.getBean("user");
}
在SpringMVC的xml文件中手动注册对应的bean:
如:
<bean id="user" class="XX.user.User"></bean>
网友评论