KSI일기장
0512 spring AOP 중 발생 오류(스케쥴러 동작) java.lang.IllegalStateException: No thread-bound request found: 본문
0512 spring AOP 중 발생 오류(스케쥴러 동작) java.lang.IllegalStateException: No thread-bound request found:
MyDiaryYo 2023. 5. 12. 19:16오류내용:
java.lang.IllegalStateException: No thread bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
try {
//HttpServletRequest 얻어오기
//단, 스프링 스케줄러 동작 시 예외 발생(스케줄러는 요청객체가 존재하지 않는다)
HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
Member loginMember = (Member)req.getSession().getAttribute("loginMember");
str += "ip : " + getRemoteAddr(req);
if(loginMember != null) {
str += "(email : " + loginMember.getMemberEmail() + " ) ";
}
} catch (Exception e) {
str += "스케줄러 동작";
e.printStackTrice();
}
logger.info(str);
}
원인:
java.lang.IllegalStateException에러가 발생하면 여러가지 이유가 있겠지만
1.해당 Controller.java 파일의 Mapping에 문제가 발생한 것일 수 있다
2. 나같은 경우에는 1번의 문제는 아니고 위 구문에 HttpServletRequest와 스케쥴러 관련된 문제였다
catch (Exception e) {
str += "스케줄러 동작";
e.printStackTrice();
에서 e.printStackTrice(); 적어줘서 표시되는 오류다.
HttpServletRequest 얻어오면
스프링 스케줄러 동작 시 예외 발생시킨다
(스케줄러는 요청객체가 존재하지 않는다)
결론:
스케쥴러 동작이 있어서 예외를 발생시킨것이니 문제될거 없다
e.printStackTrice(); 지워주면 문제될것도 없고 에러도 뜨지 않는다
'Spring' 카테고리의 다른 글
spring에러 beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ..... (0) | 2023.05.15 |
---|---|
spring에러 java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory (0) | 2023.05.15 |
0512 spring AOP 정의 (0) | 2023.05.12 |
spring, java 개행문자(줄바꿈) <br> -> \n replace 처리 (1) | 2023.05.12 |
spring XSS(크로스 사이트 스크립팅) (0) | 2023.05.12 |