티스토리 뷰

XML로 설정되어 있던 spring web application context를 Java Config 로 변환하는 과정에 오류가 발생하였다. 

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.
	at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
	at template.login.CustomAuthenticationProvider.authenticate(CustomAuthenticationProvider.java:47)
	at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:175)
	at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:200)

No thread-bound request found.. 

 

debug를 해서 어디서 오류가 났는지 따라가 보니 다음 장소에서 오류가 났다. 

 

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    ...	
    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();

RequestContextHolder를 생성하지 못하는 문제였다. 

 

RequestContextHolder를 생성해주기 위해서는 RequestContextListener가 필요하다. 이것은 다음과 같이 생성할 수 있다.

 

@Bean 
public RequestContextListener requestContextListener(){
    return new RequestContextListener();
} 

적당한 곳에 위와 같이 RequestContextListener Bean을 생성해주도록 하자. 

 

끝!

댓글
최근에 올라온 글
최근에 달린 댓글
«   2024/05   »
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