Spring MVC 处理程序拦截器,带有 pathparam 的排除路径模式

Som*_*kar 6 spring spring-mvc

我已经编写了一个 HandlerInterceptorAdapter 实现,并希望排除在注册令牌时对用户进行身份验证和刷新用户的路径模式,thje 资源的 URLS 主要将电子邮件地址作为路径参数,以下哪个代码片段是有效的这样做的表格

 @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/*/someresource/*");
    }
Run Code Online (Sandbox Code Playgroud)

或者

@Override
public void addInterceptors(InterceptorRegistry registry) {
    super.addInterceptors(registry);

    registry.addInterceptor(new AuthorizationInterceptor()).excludePathPatterns("/somepath/{email}/someresource/*");
}
Run Code Online (Sandbox Code Playgroud)

编辑:::

使用 PatternMatcher 增强了代码,仍然无法正常工作

 @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);

        registry.addInterceptor(new AuthorizationInterceptor())
                .excludePathPatterns(
                        "/somepath",
                        "/somepath/*/authenticate",
                        "somapath/*/someresource/verify"
                ).pathMatcher(new AntPathMatcher());
    }
Run Code Online (Sandbox Code Playgroud)

Sau*_*abh 5

尝试这个:

@Override
public void addInterceptors(InterceptorRegistry registry) {
    super.addInterceptors(registry);

    registry.addInterceptor(new AuthorizationInterceptor())
            .excludePathPatterns(
                    "/somepath",
                    "/somepath/**/authenticate",
                    "somapath/**/someresource/verify"
            ).pathMatcher(new AntPathMatcher());
}
Run Code Online (Sandbox Code Playgroud)

映射使用以下规则匹配 URL:

? matches one character
* matches zero or more characters
** matches zero or more directories in a path
Run Code Online (Sandbox Code Playgroud)