@ControllerAdvice@RestControllerAdvice都可以指向控制器的一个子集:

// 指向所有带有注解@RestController的控制器
@ControllerAdvice(annotations = RestController.class)
public class AnnotationAdvice {} // 指向所有指定包中的控制器
@ControllerAdvice("org.example.controllers")
public class BasePackageAdvice {} // 指向所有带有指定签名的控制器
@ControllerAdvice(assignableTypes = {ControllerInterface.class, AbstractController.class})
public class AssignableTypesAdvice {}
 @Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Controller
@ResponseBody
public @interface RestController
A convenience annotation that is itself annotated with @Controller and @ResponseBody.
Types that carry this annotation are treated as controllers where @RequestMapping methods assume @ResponseBody semantics by default. NOTE: @RestController is processed if an appropriate HandlerMapping-HandlerAdapter pair is configured such as the RequestMappingHandlerMapping-RequestMappingHandlerAdapter
pair which are the default in the MVC Java config and the MVC namespace.
 @Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Component
public @interface ControllerAdvice
Indicates the annotated class assists a "Controller".
Serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning. It is typically used to define @ExceptionHandler, @InitBinder, and @ModelAttribute methods that apply to all @RequestMapping methods. One of annotations(), basePackageClasses(), basePackages() or its alias value() may be specified to define specific subsets of Controllers to assist.
When multiple selectors are applied, OR logic is applied - meaning selected Controllers should match at least one selector. The default behavior (i.e. if used without any selector), the @ControllerAdvice annotated class will assist all known Controllers. Note that those checks are done at runtime, so adding many attributes and using multiple strategies may have negative impacts (complexity, performance).

https://docs.spring.io/spring-framework/docs/5.0.0.M1/javadoc-api/

区别@ControllerAdvice 和@RestControllerAdvice的更多相关文章

  1. SpringMVC常用注解(三)

    一.@Controller .@RestController 和 @ControllerAdvice 1. @Controller @Controller 用于标记在一个类上,使用它标记的类就是一个S ...

  2. springboot 详解RestControllerAdvice(ControllerAdvice)(转)

    springboot 详解RestControllerAdvice(ControllerAdvice)拦截异常并统一处理简介 @Target({ElementType.TYPE}) @Retentio ...

  3. Spring Boot 系列 @ControllerAdvice 拦截异常并统一处理

    ControllerAdvice用法解析 简介 通过@ControllerAdvice注解可以将对于控制器的全局配置放在同一个位置. 注解了@Controller的类的方法可以使用@Exception ...

  4. @RestControllerAdvice注解使用

    在spring 3.2中,新增了@ControllerAdvice,@RestControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder.@Mode ...

  5. 精通Spring Boot---使用@ControllerAdvice处理异常

    在Spring 3.2中,新增了@ControllerAdvice.@RestControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder.@Mode ...

  6. 全局异常捕获处理-@ControllerAdvice+@HandleException

    涂涂影院管理系统这个demo中有个异常管理的标签,用于捕获 涂涂影院APP用户异常信息 ,有小伙伴好奇,排除APP,后台端的是如何处理全局异常的,故项目中的实际应用已记之. 关于目前的异常处理 在使用 ...

  7. SpringBoot - @ControllerAdvice 处理异常

    在Spring 3.2中,新增了@ControllerAdvice.@RestControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder.@Mode ...

  8. 使用@ControllerAdvice处理异常

    在Spring 3.2中,新增了@ControllerAdvice.@RestControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder.@Mode ...

  9. SpringBoot之常用注解

    在spring boot中,摒弃了spring以往项目中大量繁琐的配置,遵循约定大于配置的原则,通过自身默认配置,极大的降低了项目搭建的复杂度.同样在spring boot中,大量注解的使用,使得代码 ...

随机推荐

  1. I/O复习

    I/O流之字符流 问题:字节流和字符流区别? java1.0只提供了字节流,分为输出流(Inputstream)和输入流(Outputstream), 以字节为单位来读取或写入数据,以二进制来处理数据 ...

  2. 深入浅出JVM

    这篇文章简要解析了JVM的内部结构.下面这幅图展示了一个典型的JVM(符合JVM Specification Java SE 7 Edition)所具备的关键内部组件. 上图展示的所有这些组件都将在下 ...

  3. poj 1274 The Perfect Stal - 网络流

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

  4. Python3基础 type 获得变量的类型

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. 完美解决vim在终端不能复制的问题

    以前 用xshell,或者其他工具ssh到远程服务器,vim不能复制,搜索说是vim的 -xterm_clipboard没有开启. 今天发现,至少鼠标复制是不需要这个东东的! 在stackoverfl ...

  6. ubuntu启动google_chrome报错:FATAL:nss_util.cc(632)] NSS_VersionCheck("3.26") failed. NSS >= 3.26 is required. Please upgrade to the latest NSS

    一.背景: jello@jello:~$ lsb_release -aNo LSB modules are available.Distributor ID:    Ubuntu KylinDescr ...

  7. linux下的下载之道

    a.场景: 平时会使用百度网盘下载电影,但是用ios版的百度云实在是有点慢,而平时不用windows,因此只能在linux上寻找解决之道. b.背景(我正在使用中): linux:ubuntu 14. ...

  8. 【分布式计算】30分钟概览Spark分布式计算引擎

    本文主要帮助初学者快速了解Spark,不会面面俱到,但核心一定点到. Spark是继Hadoop之后的下一代分布式内存计算引擎,于2009年诞生于加州大学伯克利分校AMPLab实验室,现在主要由Dat ...

  9. NS3 一个小问题

    可能会在执行./waf 命令的时候遇到这个问题,比如我想编译 /home/wasdns/Documents/NS3/ns-3.17/scratch 目录下的一个文件:newnsthree.cpp 编译 ...

  10. CSU 1808 地铁(最短路变形)

    http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1808 题意: Bobo 居住在大城市 ICPCCamp. ICPCCamp 有 n 个地铁站, ...