Interceptor和filter区别

Spring种filter和Interceptor傻傻分不清,因此简单的做个记录

filter即过滤器,是属于Java的。

Interceptor即拦截器,是属于Spring的,是用于面向切面编程的(指定用于web开发中)。

在执行上,filter的执行靠server(例如:tomcat),Interceptor的执行靠Spring容器,且执行顺序方面:filter要早于Interceptor执行。

在能力上,Spring项目中Interceptor能做到filter能做的且能力强于filter,因此Spring项目种要优先使用filter