Spring Controller 全域性捕獲異常
阿新 • • 發佈:2019-02-18
package controllerexception;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class ControllerException {
@ExceptionHandler(value = Exception.class) public void exception(Exception e){ e.printStackTrace(); }
}
package controllerexception;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(“/test”)
public class ControllerTest {
@RequestMapping("/value") public void test(){ throw new NullPointerException(); }
}