[英]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¶m2=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.