@ControllerAdvice를 통한 예외처리 분리, 통합하기

2022. 12. 20. 17:53·Languages | Frameworks/Spring

@ControllerAdvice

@ExceptionHandler가 하나의 클래스에 대한 것이라면, @ControllerAdvice는 모든 @Controller 즉, 전역에서 발생할 수 있는 예외를 잡아 처리해주는 annotation이다.

 

예를들어 모든 jsp(ex. header)에 같은 modelAttribute를 던져줘야 한다면,  아래와 같이 사용하면 된다.

@ControllerAdvice
public class AdviceController {
		
    @ModelAttribute("modelAttribute key값")
    public String getWhereIP() {
        
        return "modelAttribute value값";
}

'Languages | Frameworks > Spring' 카테고리의 다른 글

[Redis] springboot + Redis cache(조회)  (1) 2023.11.20
[QueryDSL] N + 1 현상 해결 과정  (0) 2023.07.26
[IntelliJ] 자주쓰는 단축키 정리  (0) 2022.11.21
[Springboot] spring-security 적용기(2) - OAuth2 구글 소셜 로그인  (2) 2022.11.02
@Autowired, @Component, @Service, @Repository 등 스프링 어노테이션에 관해..  (0) 2022.11.02
'Languages | Frameworks/Spring' 카테고리의 다른 글
  • [Redis] springboot + Redis cache(조회)
  • [QueryDSL] N + 1 현상 해결 과정
  • [IntelliJ] 자주쓰는 단축키 정리
  • [Springboot] spring-security 적용기(2) - OAuth2 구글 소셜 로그인
_거누
_거누
블로그 이사했습니다! https://velog.io/@pigonhair/posts
  • _거누
    거누네룸🔑
    _거누
  • 전체
    오늘
    어제
    • 거누네룸 (83)
      • Languages | Frameworks (41)
        • Java (10)
        • Spring (23)
        • Docker (8)
      • Git | Github (1)
      • DBMS (4)
        • SQL (4)
      • DevOps | Server (3)
      • OS (6)
        • Linux (6)
      • Algorithm (26)
        • Theory (1)
        • Data Structure (7)
        • BaekJoon (5)
        • Programmers (1)
        • KBro Study (12)
  • 블로그 메뉴

    • Github
    • BaekJoon
    • solved class
    • 방명록
  • 인기 글

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
_거누
@ControllerAdvice를 통한 예외처리 분리, 통합하기
상단으로

티스토리툴바