开发者

Do Spring MVC Interceptors only intercept specific mappings?

开发者 https://www.devze.com 2023-02-14 08:58 出处:网络
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 inter

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

精彩评论

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

关注公众号