org.springframework.web.method.ControllerAdviceBean#isApplicableToBeanType(@Nullable Class<?> beanType)

判断当前类是否被ControllerAdviceBean修饰,判断依据位 ControllerAdviceBean上设置的注解@ControllerAdvice内的参数

package org.springframework.web.bind.annotation;

import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component; @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface ControllerAdvice { @AliasFor("basePackages")
String[] value() default {}; @AliasFor("value")
String[] basePackages() default {}; Class<?>[] basePackageClasses() default {}; Class<?>[] assignableTypes() default {}; Class<? extends Annotation>[] annotations() default {};
}

其内部使用 HandlerTypePredicate beanTypePredicate 进行判断,如果@ControllerAdvice注解内无参数 则可以修饰所有类。

由该段代码判断:

ControllerAdvice annotation = (beanType != null ?
AnnotatedElementUtils.findMergedAnnotation(beanType, ControllerAdvice.class) : null); if (annotation != null) {
this.beanTypePredicate = HandlerTypePredicate.builder()
.basePackage(annotation.basePackages())
.basePackageClass(annotation.basePackageClasses())
.assignableType(annotation.assignableTypes())
.annotation(annotation.annotations())
.build();
}
else {
this.beanTypePredicate = HandlerTypePredicate.forAnyHandlerType();
}
HandlerTypePredicate.forAnyHandlerType(); 改方法实现如下:
return new HandlerTypePredicate(Collections.emptySet(), Collections.emptyList(), Collections.emptyList());

=====

实际会调用org.springframework.web.method.HandlerTypePredicate#test

if (!hasSelectors()) {
return true;
}
org.springframework.web.method.HandlerTypePredicate#hasSelectors

private boolean hasSelectors() {
return (!this.basePackages.isEmpty() || !this.assignableTypes.isEmpty() || !this.annotations.isEmpty());
}

org.springframework.web.method.ControllerAdviceBean#isApplicableToBeanType 作用的更多相关文章

  1. org.springframework.web.method.HandlerMethod 与 org.springframework.messaging.handler.HandlerMethod 转换失败

    Springmvc hander.getclassclass org.springframework.web.method.HandlerMethod HandlerMethod.classclass ...

  2. org.springframework.web.filter.DelegatingFilterProxy的作用

    一.类结构 DelegatingFilterProxy类继承GenericFilterBean,间接实现了Filter,故而该类属于一个过滤器.那么就会有实现Filter中init.doFilter. ...

  3. 使用ControllerAdvice注意事项,Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]

    前言 ControllerAdvice非常好用,可以把系统内部的异常统一处理.用起来也很简单.比如,http://www.cnblogs.com/woshimrf/p/spring-web-400.h ...

  4. org.springframework.web.bind.ServletRequestDataBinde

    org.springframework.validation Class DataBinder java.lang.Object org.springframework.validation.Data ...

  5. SpringMVC文件上传报错org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

    错误信息: java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to or ...

  6. org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

    异常信息 org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable represen ...

  7. Java之——java.lang.NoSuchMethodException: [org.springframework.web.multipart.MultipartFile;.()

    转自:https://blog.csdn.net/l1028386804/article/details/65449355 ava.lang.NoSuchMethodException: [org.s ...

  8. java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

    转自:https://blog.csdn.net/iteye_17476/article/details/82651580 java.lang.ClassCastException: org.apac ...

  9. org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported

    1:先上控制台报错信息 org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not ...

随机推荐

  1. ML-对偶(Duality)问题初识

    Primal vs Dual 为什么要把原始问题(primal) 转为 对偶问题(dual), 主要原因在于, 求解方便吧大概. 对偶问题 原始问题和其对偶问题, 都是对看待同一个问题的,从不同角度, ...

  2. go frame框架,关闭启动时打印的路由列表已经debug信息

    import ( "github.com/gogf/gf/frame/g" "github.com/gogf/gf/os/glog" ) func main() ...

  3. kubelet 预留system、kube资源

    kubelet 预留system.kube资源 Kubernetes 的节点可以按照 Capacity 调度.默认情况下 pod 能够使用节点全部可用容量.这是个问题,因为节点自己通常运行了不少驱动 ...

  4. 详解Linux操作系统的iptables原理及配置

    linux网络防火墙 netfilter :内核中的框架,过滤框架,网络过滤器! iptables  :实现数据过滤.net.mangle等规则生成的工具 防火墙:硬件.软件.规则(匹配规则.处理办法 ...

  5. 【转】Web测试中定位bug方法

    在web测试过程中,经常会遇到页面中内容或数据显示错误,甚至不显示,第一反应就是BUG,进一步了解这个BUG的问题出在那里,是测试人员需要掌握的,可以简单的使用浏览器自带开发者工具.数据库工具配合去排 ...

  6. HDFS的读写流程

    1.2. 客户端向NameNode发起创建文件的请求,在NameNode上创建一个文件名,并且返回一个输出流 3.客户端向输出流发起写入数据的请求 4.输出流向NameNode请求写数据,NameNo ...

  7. spring MVC核心思想

    目录  一.前言二.spring mvc 核心类与接口三.spring mvc 核心流程图 四.spring mvc DispatcherServlet说明 五.spring mvc 父子上下文的说明 ...

  8. springboot 打包插件spring-boot-maven-plugin打包机制及内部结构分析

    今日思语:I miss you? 何解? 我错过你了?我想你了? 当下许多公司都会选择使用springboot作为服务应用开发框架,springboot框架提供了一套自己的打包机制,是通过spring ...

  9. 第1章 Spring的应用

    一.Spring 的两种核心容器:BeanFactory 和 ApplicationContext(都通过xml加载Bean的) 二.通过ApplicationContext实例化: 1.通过Clas ...

  10. 学习:窗口创建以及消息处理basic.c

    WNDCLASS结构: Windows 的窗口总是基于窗口类来创建的,窗口类同时确定了处理窗口消息的窗口过程(回调函数). 在创建应用程序窗口之前,必须调用 RegisterClass 函数来注册窗口 ...