开发者

Do Spring MVC Interceptors only intercept specific mappings?

Using Spring MVC, do interc开发者_StackOverfloweptors only intercept defined controller mappings or can they also be used to intercept general requests made within the servlet context?


Spring MVC interceptors intercept only request to controllers. For intercepting other requests use Filters.

UPDATE: If you want to configure filters as Spring beans, you can use DelegatingFilterProxy, as follows:

@Component(name = "myFilter")
public class MyFilter implements Filter { ... }

(or <bean id = "myFilter" class = "...MyFilter">...</bean> in XML config).

Then, in web.xml:

<filter>
    <!-- By default, delegates to the bean of the same name -->
    <filter-name>myFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>myFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜