org.springframework.web.bind.annotation.ExceptionHandler类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(296)

本文整理了Java中org.springframework.web.bind.annotation.ExceptionHandler类的一些代码示例,展示了ExceptionHandler类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExceptionHandler类的具体详情如下:
包路径:org.springframework.web.bind.annotation.ExceptionHandler
类名称:ExceptionHandler

ExceptionHandler介绍

暂无

代码示例

代码示例来源:origin: apache/kylin

@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
@ResponseBody
ErrorResponse handleNotFound(HttpServletRequest req, Exception ex) {
  return new ErrorResponse(req.getRequestURL().toString(), ex);
}

代码示例来源:origin: spring-projects/spring-framework

private void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result) {
  ExceptionHandler ann = AnnotatedElementUtils.findMergedAnnotation(method, ExceptionHandler.class);
  Assert.state(ann != null, "No ExceptionHandler annotation");
  result.addAll(Arrays.asList(ann.value()));
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-dataflow-admin-starter

/**
 * Handles the general error case. Report server-side error.
 */
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ResponseBody
public VndErrors onException(Exception e) {
  String logref = logError(e);
  String msg = StringUtils.hasText(e.getMessage()) ? e.getMessage() : e.getClass().getSimpleName();
  return new VndErrors(logref, msg);
}

代码示例来源:origin: roncoo/spring-boot-demo

/**
 * 统一异常处理
 * 
 * @param exception
 *            exception
 * @return
 */
@ExceptionHandler({ RuntimeException.class })
@ResponseStatus(HttpStatus.OK)
public ModelAndView processException(RuntimeException exception) {
  logger.info("自定义异常处理-RuntimeException");
  ModelAndView m = new ModelAndView();
  m.addObject("roncooException", exception.getMessage());
  m.setViewName("error/500");
  return m;
}

代码示例来源:origin: spring-projects/spring-framework

@ExceptionHandler(Exception.class)
  @ResponseBody
  String handleException(Exception exception);
}

代码示例来源:origin: sqshq/piggymetrics

@ExceptionHandler(IllegalArgumentException.class)
  @ResponseStatus(HttpStatus.BAD_REQUEST)
  public void processValidationError(IllegalArgumentException e) {
    log.info("Returning HTTP 400 Bad Request", e);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@ExceptionHandler({
    HttpRequestMethodNotSupportedException.class,
    HttpMediaTypeNotSupportedException.class,
@Nullable
public final ResponseEntity<Object> handleException(Exception ex, WebRequest request) throws Exception {
  HttpHeaders headers = new HttpHeaders();

代码示例来源:origin: spring-projects/spring-framework

@ExceptionHandler(TestException.class)
public ModelAndView handleException() {
  return new ModelAndView("view", HttpStatus.UNPROCESSABLE_ENTITY);
}

代码示例来源:origin: spring-projects/spring-framework

@ExceptionHandler
  public void myPath2(Exception ex, HttpServletResponse response) throws IOException {
    response.getWriter().write(ex.getMessage());
  }
}

代码示例来源:origin: wuyouzhuguli/FEBS-Shiro

@ExceptionHandler(value = AuthorizationException.class)
public Object handleAuthorizationException(HttpServletRequest request) {
  if (HttpUtils.isAjaxRequest(request)) {
    return ResponseBo.error("暂无权限,请联系管理员!");
  } else {
    ModelAndView mav = new ModelAndView();
    mav.setViewName("error/403");
    return mav;
  }
}

代码示例来源:origin: spring-projects/spring-data-rest

/**
 * Send {@code 405 Method Not Allowed} and include the supported {@link org.springframework.http.HttpMethod}s in the
 * {@code Allow} header.
 *
 * @param o_O the exception to handle.
 * @return
 */
@ExceptionHandler
ResponseEntity<Void> handle(HttpRequestMethodNotSupportedException o_O) {
  HttpHeaders headers = new HttpHeaders();
  headers.setAllow(o_O.getSupportedHttpMethods());
  return response(HttpStatus.METHOD_NOT_ALLOWED, headers);
}

代码示例来源:origin: joshlong/bookmarks

@ResponseBody
  @ExceptionHandler(UserNotFoundException.class)
  @ResponseStatus(HttpStatus.NOT_FOUND)
  VndErrors userNotFoundExceptionHandler(UserNotFoundException ex) {
    return new VndErrors("error", ex.getMessage());
  }
}

代码示例来源:origin: roncoo/spring-boot-demo

/**
 * 统一异常处理
 * 
 * @param exception
 *            exception
 * @return
 */
@ExceptionHandler({ Exception.class })
@ResponseStatus(HttpStatus.OK)
public ModelAndView processException(Exception exception) {
  logger.info("自定义异常处理-Exception");
  ModelAndView m = new ModelAndView();
  m.addObject("roncooException", exception.getMessage());
  m.setViewName("error/500");
  return m;
}

代码示例来源:origin: spring-projects/spring-framework

@ExceptionHandler(Exception.class)
  @ResponseBody
  String handleException(Exception exception);
}

代码示例来源:origin: hs-web/hsweb-framework

@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
ResponseMessage handleException(IllegalArgumentException exception) {
  String msg = exception.getMessage();
  if (null == msg) {
    logger.error(msg = "参数错误", exception);
  }
  return ResponseMessage.error(400, msg);
}

代码示例来源:origin: org.springframework/spring-webmvc

@ExceptionHandler({
    HttpRequestMethodNotSupportedException.class,
    HttpMediaTypeNotSupportedException.class,
@Nullable
public final ResponseEntity<Object> handleException(Exception ex, WebRequest request) throws Exception {
  HttpHeaders headers = new HttpHeaders();

代码示例来源:origin: cloudfoundry/uaa

@ExceptionHandler(UaaPrincipalIsNotInSession.class)
public ModelAndView handleUaaPrincipalIsNotInSession() {
  return new ModelAndView("redirect:/login", Collections.emptyMap());
}

代码示例来源:origin: spring-projects/spring-framework

@ExceptionHandler
  public void handleException(Exception ex, Writer writer) throws IOException {
    writer.write(ClassUtils.getShortName(ex.getClass()));
  }
}

代码示例来源:origin: joshlong/bookmarks

@ResponseBody
  @ExceptionHandler(UserNotFoundException.class)
  @ResponseStatus(HttpStatus.NOT_FOUND)
  VndErrors userNotFoundExceptionHandler(UserNotFoundException ex) {
    return new VndErrors("error", ex.getMessage());
  }
}

代码示例来源:origin: apache/kylin

@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(ForbiddenException.class)
@ResponseBody
ErrorResponse handleForbidden(HttpServletRequest req, Exception ex) {
  return new ErrorResponse(req.getRequestURL().toString(), ex);
}

相关文章