想在filter中使用依賴注入的對象,配置以下: web.xml中web
<filter> <filter-name>sessionFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>sessionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
spring 配置文件中spring
<bean id="sessionFilter" class="com.eccl.SessionFilter"> </bean>
filter文件session
public class SessionFilter implements Filter{ @Resource private SysUserService sysUserService; @Resource private SessionAuthenticationStrategy sessionStrategy = new NullAuthenticatedSessionStrategy(); @Override public void destroy() { } @Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { } @Override public void init(FilterConfig arg0) throws ServletException { } }