繁体   English   中英

Spring 引导拦截器 - 如何排除一些 URL

[英]Spring Boot interceptor - how to exclude some URL

我想从我的全局拦截器(整个控制器)中排除这个端点 URL:

@RequestMapping(value = "/api/rest/v1/company/{companyId}/store")
@RestController()
@RequiredArgsConstructor
@Slf4j
public class StoreController {


@GetMapping(with request params)

@PostMapping()

我尝试了很多选择,例如:

 @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(new GlobalInterceptor(taService, authService))
                .excludePathPatterns("**/store")
                .pathMatcher(new AntPathMatcher());
    }

但没有成功。

此外,我想排除带有查询参数的模式,例如:

/api/rest/v1/company/{companyId}/store?param1=abc&param2=def

也许我应该排除所有 Swagger 网址

我找到了一个解决方案(缺少斜杠“/”):

 @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(new GlobalInterceptor(taService, authService))
                .excludePathPatterns("/**/store")
                .pathMatcher(new AntPathMatcher());
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM