首页 > 编程语言 > 详细

自定义Springboot全局异常类

时间:2019-12-26 22:40:01      阅读:122      评论:0      收藏:0      [点我收藏+]

简要说明

如何实现网上文章基本是随便一搜就可以很快找到, 这里不再赘述.

Spring-web和Spring-webmvc

通过idea查看到两个注解位于 spring-web-5.2.2.RELEASE.jar包内,.

而这里maven依赖有spring web 和spring webmvc 两个包;

查询到spring web主要提供了HTTP的功能集成,

而spring-webmvc基于spring-web, 从而提供servlet功能. (参考: Maven dependency spring-web vs spring-webmvc)

2.2.5 Web
The Web layer consists of the spring-web, spring-webmvc, spring-websocket, and spring-webmvc-portlet modules.

The spring-web module provides basic web-oriented integration features such as multipart file upload functionality and the initialization of the IoC container using Servlet listeners and a web-oriented application context. It also
contains an HTTP client and the web-related parts of Spring’s remoting support.

The spring-webmvc module (also known as the Web-Servlet module) contains Spring’s model-view-controller (MVC) and REST Web Services implementation for web applications. Spring’s MVC framework provides a clean > separation between domain model code and web forms and integrates with all of the other features of the Spring Framework.

The spring-webmvc-portlet module (also known as the Web-Portlet module) provides the MVC implementation to be used in a Portlet environment and mirrors the functionality of the Servlet-based spring-webmvc module.

技术分享图片

两个注解

  • @ControllerAdvice
@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 {};
}
  • @ExceptionHandler
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ExceptionHandler {
    Class<? extends Throwable>[] value() default {};
}

自定义Springboot全局异常类

原文:https://www.cnblogs.com/52liming/p/12104598.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!