我正在使用 Spring Boot 构建 REST API,现在尝试创建一个自定义过滤器类,我需要在其中访问请求将调用的资源方法。我需要它来检查该方法是否用某个注释进行注释,例如
@Component
@ApplicationScope
public class MyFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
Method method = // get the target method somehow
if (method.isAnnotationPresent(MyAnnotation.class)) {
// business logic here
}
filterChain.doFilter(request, response);
}
}
Run Code Online (Sandbox Code Playgroud)
使用 RESTEasy 我会做这样的事情
@Context
private ResourceInfo resourceInfo;
Run Code Online (Sandbox Code Playgroud)
其中 ResourceInfo 具有获取作为请求目标的资源类和方法的方法。Spring Boot 中是否有类似的类可以完成相同的工作?
| 归档时间: |
|
| 查看次数: |
1367 次 |
| 最近记录: |