티스토리 뷰
Interceptor에 오류페이지를 타지 않게 하는 방법은 간단하다.
다만 이 방법은 오류페이지에 대한 컨트롤러를 따로 사용 할 때에만 유용한 방법 같다
package hello.exception;
import hello.exception.filter.LogFilter;
import hello.exception.interceptor.LogInterceptor;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LogInterceptor())
.order(1)
.addPathPatterns("/**")
.excludePathPatterns("/css/*","*.ico","/error","/error-page/**"); //Filter와 다르게 DispatcherType을 넣을 수 없다.
// 대신 excludePathPatterns 이라는 강력한 메소드가 있어서 error-page 관련을 빼면 된다.
}
//@Bean
public FilterRegistrationBean logFilter(){
FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
filterRegistrationBean.setFilter(new LogFilter());
filterRegistrationBean.setOrder(1);
filterRegistrationBean.addUrlPatterns("/*");
filterRegistrationBean.setDispatcherTypes(DispatcherType.REQUEST,DispatcherType.ERROR); //요청과 에러일 경우에만 호출된다.
return filterRegistrationBean;
}
}
registry 객체에 에러 페이지 url에 해당하는 (/error-page/**) 모든 페이지에 대해 인터셉터를 타지 않게 제한 하면 끝이다.
'dev_공부일지 > spring boot + intelliJ' 카테고리의 다른 글
api 예외처리는 html이면 안된다. (0) | 2023.12.03 |
---|---|
스프링 부트는 자동으로 에러페이지를 작성해준다. BasicErrorController (1) | 2023.12.02 |
ErrorPage 만들기 (0) | 2023.12.01 |
ArgumentResolver 직접 어노테이션 만들기 (0) | 2023.11.29 |
인터셉터 1 (1) | 2023.11.22 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 향해99
- exception
- 항해플러스
- 항해99
- 스프링부트
- rejectValue
- filter
- Intercepter
- Java
- thymleaf
- reject
- HTTP
- 리터럴
- 향해플러스
- ArgumentResolver
- SpringBoot
- 백엔드 개발자 공부
- 백엔드 개발자 역량
- 컨트
- BindingResult
- React
- hypertexttransferprotocol
- jpa api
- 스프링공부
- react실행
- 로그인
- 예외처리
- 인터셉터
- JPA
- 향해플러스백엔드
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함