java - Spring Boot 拦截器 - 如何排除某些 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());
}
推荐阅读
- oracle - Oracle 11.2.0.1(32 位)给出 ORA-12547: TNS:lost contact while creating DB with dbca
- c# - 如何获取 xaml 的内容
在 .cs 中? - asp.net-core - 如何在 IIS 上部署 beta 版本?
- python - 如何遍历 Python 列表及其列表元素,在每个元素中拆分字符串并写出新列表
- python - 带有 2 个定义相同方法的 Mixin 的 CBV - 如何让每个 Mixin 执行自己的代码?
- html - 将“https:”附加到以 src=// 开头的汤中的链接
- php - Cakephp 3 - 使用文件上传将大型 CSV 导入数据库 错误 503 服务不可用
- reactjs - React Native App 总是在登录屏幕上打开
- flutter - 在 Flutter 中的 FocusedBorder 上 TextFormFeild 的 LabelText 无法正确显示
- c# - 如何使用 MemoryStream 将数据从一种形式发送到另一种形式