簡體   English   中英

Spring Boot攔截器無論如何都被稱為排除模式

[英]Spring Boot Interceptor called anyway of exclude pattterns

已向以下人員注冊攔截器:

@Override
protected void addInterceptors(final InterceptorRegistry registry) {
    registry.addInterceptor(new ThymeleafLayoutInterceptor()).addPathPatterns("/**").excludePathPatterns("/json/**").excludePathPatterns("/static/**");
}

以我的理解,對於每個請求都應調用攔截器,但對於
/靜態的/
要么
/ json /在他們的路徑。 但是,攔截器似乎是從每個資源中調用的,也都是從路徑中具有靜態的資源調用的。

我的攔截器的PostHandle方法中的打印輸出

final ResourceHttpRequestHandler h = (ResourceHttpRequestHandler) handler;
System.out.println(h.getLocations());

結果是

[class path resource [static/]]

我嘗試過像
1. /靜態/ **
2. / static / *,
3. / static /
4.靜態/

這怎么可能?我該如何解決這個問題?

您兩次調用excludePathPatterns。

這應該做的工作

@Override
protected void addInterceptors(final InterceptorRegistry registry) {
    registry.addInterceptor(new ThymeleafLayoutInterceptor())
            .addPathPatterns("/**")
            .excludePathPatterns("/json/**", "/static/**");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM