본문으로 바로가기

ExceptionHandler

category Backend/Spring 2017. 8. 23. 14:29
    반응형
    1. package com.ekiras.handler.exception;  
    2.   
    3. import com.ekiras.exception.BaseException;  
    4. import org.springframework.http.HttpStatus;  
    5. import org.springframework.web.bind.annotation.ControllerAdvice;  
    6. import org.springframework.web.bind.annotation.ExceptionHandler;  
    7. import org.springframework.web.bind.annotation.ResponseStatus;  
    8. import org.springframework.web.bind.annotation.RestController;  
    9.   
    10. /** 
    11.  * @author ekansh 
    12.  * @since 19/2/16 
    13.  */  
    14. @ControllerAdvice  
    15. @RestController  
    16. public class GlobalExceptionHandler {  
    17.   
    18.     @ResponseStatus(HttpStatus.BAD_REQUEST)  
    19.     @ExceptionHandler(value = BaseException.class)  
    20.     public String handleBaseException(BaseException e){  
    21.         return e.getMessage();  
    22.     }  
    23.   
    24.     @ExceptionHandler(value = Exception.class)  
    25.     public String handleException(Exception e){return e.getMessage();}  
    26.   
    27.   
    28. }  




    참고사이트


    http://springboot.tistory.com/33

    반응형