org.springframework.web.method.ControllerAdviceBean#isApplicableToBeanType 作用
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 作用的更多相关文章
- org.springframework.web.method.HandlerMethod 与 org.springframework.messaging.handler.HandlerMethod 转换失败
Springmvc hander.getclassclass org.springframework.web.method.HandlerMethod HandlerMethod.classclass ...
- org.springframework.web.filter.DelegatingFilterProxy的作用
一.类结构 DelegatingFilterProxy类继承GenericFilterBean,间接实现了Filter,故而该类属于一个过滤器.那么就会有实现Filter中init.doFilter. ...
- 使用ControllerAdvice注意事项,Ambiguous @ExceptionHandler method mapped for [class org.springframework.web.bind.MethodArgumentNotValidException]
前言 ControllerAdvice非常好用,可以把系统内部的异常统一处理.用起来也很简单.比如,http://www.cnblogs.com/woshimrf/p/spring-web-400.h ...
- org.springframework.web.bind.ServletRequestDataBinde
org.springframework.validation Class DataBinder java.lang.Object org.springframework.validation.Data ...
- 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 ...
- org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
异常信息 org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable represen ...
- Java之——java.lang.NoSuchMethodException: [org.springframework.web.multipart.MultipartFile;.()
转自:https://blog.csdn.net/l1028386804/article/details/65449355 ava.lang.NoSuchMethodException: [org.s ...
- 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 ...
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
1:先上控制台报错信息 org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not ...
随机推荐
- php根据二维数组中的某一元素相等,另一个元素相加
二维数组:$taskData Array ( [0] => Array ( [area] => 1 [winsFlag] => 7 [count] => 3 ) [1] =&g ...
- rest framework 之解析器
一.示例 1.api/urls.py from django.urls import path, re_path from api.views import UserView, ParserView ...
- 【TCP】TCP三次握手与四次挥手
一.TCP三次握手 第一次握手:Client 将标志位 SYN=1 ,随机产生一个值 seq=J ,并将该数据包发送给 Server .此时,Client 进入SYN_SENT 状态,等待 Serve ...
- 了解python-FAQ
python FAQ 参考: https://docs.python.org/zh-cn/3.7/faq/design.html#why-are-python-strings-immutable wh ...
- 2019年杭电多校第二场 1002题Beauty Of Unimodal Sequence(LIS+单调栈)
题目链接 传送门 思路 首先我们对\(a\)正反各跑一边\(LIS\),记录每个位置在前一半的\(LIS\)中应该放的位置\(ans1[i]\),后一半的位置\(ans2[i]\). 对于字典序最小的 ...
- Selenium_webdriver+java通过读取firefox、chrome的cookie文件,实现自动登录
遇到过很多问题,通过查资料得出的最终结果!
- Gradle 知识点
mac 系统中,下载的 Gradle 压缩包解压后存储的文件夹:/Users//.gradle/wrapper/dists 当Gradle运行时,会根据settings.gradle的配置情况,构建一 ...
- Nuxt.js 提供了两种发布部署应用的方式:服务端渲染应用部署 和 静态应用部署
官方网址:https://zh.nuxtjs.org/guide/commands/#%E5%8F%91%E5%B8%83%E9%83%A8%E7%BD%B2
- .net 异常
ArgumentNullException 当将空引用(在 Visual Basic 中为 Nothing)传递给不接受它作为有效参数的方法时引发的异常.
- async/await 和 trycatch/throwable机制类似
async/await 和 trycatch/throwable机制类似