Spring Boot Global Exception configuration, handling exception controller needs and the method of exception occurs in a class. Using Controlleradvice annotations
PackageCom.li.controller;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.Model;ImportOrg.springframework.web.bind.annotation.ControllerAdvice;ImportOrg.springframework.web.bind.annotation.ExceptionHandler;Importorg.springframework.web.bind.annotation.RequestMapping;Importorg.springframework.web.bind.annotation.ResponseBody; @Controller Public classExceptionhandlercontroller {@RequestMapping ("/exceptiontest") @ResponseBody PublicString Test ()throwsexception{System.out.println (Test); inti=1/0; returninteger.tostring (i); } @ControllerAdviceclasshandlerexception{@ExceptionHandler (Exception.class) @ResponseBody PublicString Defultexcepitonhandler (Exception e) {//return "{\" error\ ": \" Error\ "}"; return"Error"; } }}
79424142
Spring Boot Global Exception configuration