공부/JAVA | JSP&Servlet | Spring

[Spring 에러] HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter

bumcrush 2019. 5. 9. 13:58
반응형

[Spring 에러] HTTP Status 500 - Handler processing failed; 

nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter

 

각설

구글 로그인 api를 Spring으로 구현하려고 연습을 하던 중이었다.

그러다 마주친 에러,, 에러 내용 중 jackson이 있길래

jackson maven문제인 줄 알고

버전 별로 계속 바꿔가면서 실행해봤는데, 오류는 똑같다.

진짜 2틀 동안 개 고생하다가

구글 로그인 포기하고 페북으로 해보자 했는데,

페북 https 문제 해결하고 나니깐 

또 또 또 똑같은 에러가 떳다!!!!!

 

와 진짜 절망을 맛 보았다..

그러다 혹시나해서 spring 버전을 손보니깐 해결을 봤다.

이루어 말 할 수 없는 기쁨..

 

에러 내용

HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter


HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter
type Exception report

message Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter
	org.springframework.social.oauth2.OAuth2Template.createRestTemplate(OAuth2Template.java:215)
	org.springframework.social.oauth2.OAuth2Template.getRestTemplate(OAuth2Template.java:265)
	org.springframework.social.oauth2.OAuth2Template.postForAccessGrant(OAuth2Template.java:242)
	org.springframework.social.oauth2.OAuth2Template.exchangeForAccess(OAuth2Template.java:144)
	com.facebook.login.HomeController.facebookSignInCallback(HomeController.java:60)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:498)
	org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
	org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
	org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
	org.springframework.social.oauth2.OAuth2Template.createRestTemplate(OAuth2Template.java:215)
	org.springframework.social.oauth2.OAuth2Template.getRestTemplate(OAuth2Template.java:265)
	org.springframework.social.oauth2.OAuth2Template.postForAccessGrant(OAuth2Template.java:242)
	org.springframework.social.oauth2.OAuth2Template.exchangeForAccess(OAuth2Template.java:144)
	com.facebook.login.HomeController.facebookSignInCallback(HomeController.java:60)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:498)
	org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


note The full stack trace of the root cause is available in the Apache Tomcat/8.0.46 logs.

 

원인

Jackson 라이브러리 버전과 spring 라이브러리 버전이 호환이 안되서

 

 

해결방법

1. jackson dependency 버전 수정 

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-core</artifactId>
	    <version>2.9.7</version>
	</dependency>

위를 복사해서 pom.xml에 붙여넣는다.

(혹시 다른 jackson-core 가 있으면 그냥 지우고 저거 붙여넣는다.)

 

 

2. Spring 버전 변경

pom.xml에 윗부분에 보면

아래 사진 처럼 스프링프레임 워크 버전이 적혀 있을 것이다.

 

변경 전 

나는 3.1.1RELEASE로 되어있는데, 

이것을 4.2.4. RELEASE로 변경한다.

 

 

변경 후

이렇게 변경하고 저장 한 뒤 실행해 보자..

 

에러 지옥 탈출 성공

 

 

MappingJackson2HttpMessageConverter / 구글 로그인 API 에러 / 페이스북 로그인 API 에러 / Jackson 에러 /

nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter

  • 현재글[Spring 에러] HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter