코딍코딍
코딩기록
코딍코딍
전체 방문자
오늘
어제
  • 분류 전체보기 (271)
    • 개발 (2)
    • Java (1)
    • 스프링 (28)
    • JPA (11)
    • Git (3)
    • 알고리즘 (160)
      • 백준 (132)
      • 프로그래머스 (8)
      • SWEA (20)
    • 토이 프로젝트 (14)
      • 간단한 Springboot CRUD (1)
      • 게시판 프로젝트 (13)
    • 알고리즘 개념정리 (8)
    • 오류 해결 (13)
    • 보류 (0)
    • AWS (5)
    • 트러블 슈팅 (0)
    • 회고 (3)
    • CS (4)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

최근 글

티스토리

hELLO · Designed By 정상우.
코딍코딍

코딩기록

오류 해결

인터셉터 등록 후 부트스트랩 적용이 안 되는 문제

2022. 8. 10. 12:58

LoginCheckInterceptor

@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("LoginCheckInterceptor 실행!");

        HttpSession session = request.getSession();
        if(session==null || session.getAttribute(SessionConst.LOGIN_MEMBER)==null) {
            log.info("미인증 사용자 요쳥");
            response.sendRedirect("/member/login");
            return false;
        }
        return true;
    }
}

WebConfig

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginCheckInterceptor())
                .order(1)
                .addPathPatterns("/**")
                .excludePathPatterns("/member/login","/member/create","member/saved/*");
    }
}

 

이렇게 인터셉터를 등록하고나서부터 부트스트랩이 적용되지 않았다.

이유는 인터셉터가 부트스트랩 경로까지 검증하여서 css, js를 가져오지 못하고 바로 "/member/login" 경로로 이동시키기 때문이다. 

 

해결방법으로는

excludePathPatterns의 경로에  "/css/**", "/js/**" 를 추가하면 css와 js의 경로는 검증에서 제외되어서 잘 가져와진다.

 

WebConfig 수정

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginCheckInterceptor())
                .order(1)
                .addPathPatterns("/**")
                .excludePathPatterns("/*","/member/login","/member/create","/member/saved/*","/css/**","/js/**");
    }
}

'오류 해결' 카테고리의 다른 글

[Spring Boot] Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. 에러  (0) 2022.12.20
깃 오류  (0) 2022.11.01
[JPA] No default constructor for entity  (0) 2022.07.18
IntelliJ 'Build cancelled while executing task' 에러  (0) 2022.06.29
Cannot resolve symbol 'springframework' 문제해결 - Intellij  (0) 2022.05.20
    '오류 해결' 카테고리의 다른 글
    • [Spring Boot] Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. 에러
    • 깃 오류
    • [JPA] No default constructor for entity
    • IntelliJ 'Build cancelled while executing task' 에러
    코딍코딍
    코딍코딍
    ㅎ2

    티스토리툴바