🥕인터셉터와 필터의 차이점
일반적으로 필터에서는 utf-8만 체크한다. 왜냐면... 굳이? 임 번거로움. 스프링에 최적화되어 기능도 쉽고 편집하기도 편함. (필터는 메서드를 오버로딩해서 사용하는데 체인 형식이므로 dochain을 반드시 해줘야한다고 함,)
아래 블로그 참고.
https://mangkyu.tistory.com/173
[Spring] 필터(Filter) vs 인터셉터(Interceptor) 차이 및 용도 - (1)
Spring은 공통적으로 여러 작업을 처리함으로써 중복된 코드를 제거할 수 있도록 많은 기능들을 지원하고 있다. 이번에는 그 중에서 필터(Filter) vs 인터셉터(Interceptor)의 차이에 대해 알아보고자
mangkyu.tistory.com
https://velog.io/@dmsgp8292/%EC%8A%A4%ED%94%84%EB%A7%81.-Filter%EC%99%80-Interceptor
velog
velog.io
🥨인터셉터 설정
: 인터셉터의 정식 명칭은 핸들러 인터셉터(Handler Intercepter). 클라이언트의 요청이 컨트롤러에 가기 전에 가로채고, 응답이 클라이언트에게 가기 전에 가로챔.
즉, 인터셉터는 DispatcherServlet 이 컨트롤러를 요청하기 전, 후에 요청과 응답을 가로채서 가공할 수 있도록 해줌.
예) 하나의 인터셉터로 프로젝트 내의 모든 요청에 로그인 여부를 확인할 수 있음.
인터셉터를 만들려면 HandlerInterceptorAdaptor 클래스를 상속받아야 함.
HandlerInterceptorAdaptor 클래스를 상속받으면 사용할 수 있는 3가지의 메서드 preHandler() postHandler() afterCompletion()가 있음
- -preHandle : 컨트롤러가 호출되기 전에 실행되는 메서드
- -postHandle : 컨트롤러가 호출되고 난 후에 실행되는 메서드
- -afterCompletion : 컨트롤러의 처리가 끝나고 화면처리까지 모두 끝나면 실행되는 메서드
인터셉터에서 제외하고 싶은 부분이 있다면 서블릿-context 에서 예외 설정을 할 수 있다.
Spring 게시판 실습
org.springframework.expression.spel.SpelEvaluationException:
오류코드
[2024-02-08 11:20:53.856] [main] WARN o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hiBoardController2': Unsatisfied dependency expressed through field 'AUTH_COOKIE_NAME'; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'evn' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
[2024-02-08 11:20:53.860] [main] ERROR o.s.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'hiBoardController2': Unsatisfied dependency expressed through field 'AUTH_COOKIE_NAME'; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'evn' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
컨트롤러에서.,,쿠키 이름 상수정의하는 데에 문제가 있는 것 같음
해결함
원인: env.xml 참조하라고 해야 되는데 evn
오류 2
[2024-02-08 14:20:21.989] [main] WARN o.s.w.c.s.XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/config/spring/root-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\project\webapps\hiboard\src\main\webapp\WEB-INF\classes\com\sist\web\mapper\HiBoardDao2.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [C:\project\webapps\hiboard\src\main\webapp\WEB-INF\classes\com\sist\web\mapper\HiBoardDao2.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.sist.model.HiBoard2'. Cause: java.lang.ClassNotFoundException: Cannot find class: com.sist.model.HiBoard2 [2024-02-08 14:20:22.003] [main] ERROR o.s.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/config/spring/root-context.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [C:\project\webapps\hiboard\src\main\webapp\WEB-INF\classes\com\sist\web\mapper\HiBoardDao2.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [C:\project\webapps\hiboard\src\main\webapp\WEB-INF\classes\com\sist\web\mapper\HiBoardDao2.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'com.sist.model.HiBoard2'. Cause: java.lang.ClassNotFoundException: Cannot find class: com.sist.model.HiBoard2
xml 오류
오류 3
The content of elements must consist of well-formed character data or markup.
이거는 xml 쿼리문 안에 들어가는 괄호'<'를 태그로 인식해서 생기는 문제.
<![CDATA[]]>
위 태그를 이용해서 해결 가능함.
'Study > Spring' 카테고리의 다른 글
[스프링] 0215 게시글 수정/삭제 (0) | 2024.02.15 |
---|---|
[스프링] 0213 수업 아카이빙 : 게시판 글쓰기 - 첨부파일 업로드 (0) | 2024.02.15 |
[스프링] 0207 스프링 아카이브 (1) | 2024.02.08 |
[스프링] 0205 수업 아카이빙 : 회원가입,회원정보수정 로직/org.apache.ibatis.binding.BindingException 에러/ ModelMap (0) | 2024.02.05 |
[스프링] 0201 수업 아카이빙 (0) | 2024.02.01 |
댓글