[SPRING] java.lang.ClassNotFoundException : org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
SPRINGjava.lang.ClassNotFoundException : org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
나는 내 프로젝트에서 스프링 통합을 사용하고있다. 부두 컨테이너에 앱을 배포 할 때 다음 예외가 발생합니다.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'integrationRequestMappingHandlerMapping': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'inboundhttpJobRequestGateway': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at com.dsths.spring.web.DsthsContextLoaderListener.configureAndRefreshWebApplicationContext(DsthsContextLoaderListener.java:97)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:771)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:411)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:763)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:247)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:706)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
at com.dsths.common.container.core.deploy.DeploymentManager.deploy(DeploymentManager.java:54)
at com.dsths.common.container.core.deploy.DeploymentManager$$FastClassByCGLIB$$f5bc43eb.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor$1.call(AsyncExecutionInterceptor.java:95)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'inboundhttpJobRequestGateway': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1035)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:939)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
at org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping.detectHandlerMethods(IntegrationRequestMappingHandlerMapping.java:103)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initHandlerMethods(AbstractHandlerMethodMapping.java:109)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.initApplicationContext(AbstractHandlerMethodMapping.java:89)
at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:117)
at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1448)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 29 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:110)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
... 49 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJackson2HttpMessageConverter
at org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.<init>(HttpRequestHandlingEndpointSupport.java:166)
at org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.<init>(HttpRequestHandlingMessagingGateway.java:72)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
... 51 more
Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.dsths.common.container.ContainerClassLoader.loadClass(ContainerClassLoader.java:136)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:429)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:382)
... 58 more
클래스 패스에는 json jackson-core-asl-1.8.3과 jackson-core-2.3.1 항아리가 있습니다. 여전히 오류가 발생합니다. 문제를 해결하는 방법?
해결법
-
==============================
1.흥미로운 것은 com.dsths.common.container.ContainerClassLoader ...입니다.
흥미로운 것은 com.dsths.common.container.ContainerClassLoader ...입니다.
스프링 통합 -http가이 ClassLoader에 의해로드되지만 MappingJackson2HttpMessageConverter와 다른 모든 스프링 웹 클래스가 다른 ClassLoader와로드 된 것처럼 보입니다.
모든 스프링 용기를 같은 클래스 로더에 넣으면 좋을 것입니다.
앱이 클래스 경로에서 MappingJackson2HttpMessageConverter를 찾을 수 없습니다. 문제는 하나의 클래스 로더가 하나의 버전을 선택하고 다른 클래스 로더가 다른 버전을 선택하는 것입니다.
-
==============================
2.이 이상한 오류도 있었어. 나는 웹 서버 (tomcat) webapps / myapp / WEB-INF / lib의 항아리에서 검색을 수행했으며 클래스는 거기에있었습니다.
이 이상한 오류도 있었어. 나는 웹 서버 (tomcat) webapps / myapp / WEB-INF / lib의 항아리에서 검색을 수행했으며 클래스는 거기에있었습니다.
직장에서 또 다른 프로젝트를보고 같은 잭슨 병을 사용했을 때 사라졌습니다.
원래 나는 다음과 같은 것을 가지고 있었다.
jackson-core-2.4.3.jar jackson-databind-2.4.3.jar
나는 이것을 제거하고 다음을 추가했다 (WEB-INF / lib에 패키지 됨) :
jackson-mapper-asl-1.9.13.jar jackson-datatype-jsr310-2.5.0.jar jackson-datatype-joda-2.5.0.jar jackson-databind-2.5.0.jar jackson-core-2.5.0.jar jackson-annotations-2.5.0.jar
저는 Windows에서 Tomcat 7을 실행하고 있습니다. Java 1.6 사용 (Tomcat에서 컴파일 및 런타임 용)
servlet.xml :
<beans:bean id="jacksonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" > </beans:bean> <beans:bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <beans:property name="messageConverters"> <beans:list> <beans:ref bean="jacksonMessageConverter" /> </beans:list> </beans:property> </beans:bean>
도움이 될 경우, jats를 검색하기 위해 cygwin에서 다음 쉘을 실행합니다.
JAR="C:/java/Java/jdk1.7.0_71/bin/jar.exe" srchdir="c:/appservers/apache-tomcat-7.0.57/webapps/my-web/WEB-INF/lib" echo "SEARCH FOLDER: $srchdir" find $srchdir -print | grep '\.jar$' | while read f do $JAR tf $f | grep 'MappingJackson2HttpMessageConverter\.class' >/dev/null 2>&1 [ $? -eq 0 ] && echo "==> $f" && $JAR tf $f | grep MappingJackson2HttpMessageConverter\.class done
-
==============================
3.일반적으로, MappingJackson2HttpMessageConverter 클래스는 spring-web.jar (또는 spring-web-x.y.z-RELEASE.jar)에 존재하므로 classpath에 추가하거나 maven을 사용하여 다음과 같은 의존성을 추가해야합니다.
일반적으로, MappingJackson2HttpMessageConverter 클래스는 spring-web.jar (또는 spring-web-x.y.z-RELEASE.jar)에 존재하므로 classpath에 추가하거나 maven을 사용하여 다음과 같은 의존성을 추가해야합니다.
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>x.y.z.RELEASE</version> </dependency>
Artem Bilan 주석 편집 :
일반적으로 maven을 사용한다면, 스프링 통합 -http의 의존성으로 존재해야한다.
from https://stackoverflow.com/questions/26140993/java-lang-classnotfoundexception-org-springframework-http-converter-json-mappin by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] Spring 보안은 UserDetails 객체를 반환하지 않으며, 사용자 이름 만 반환합니다. (0) | 2019.05.19 |
---|---|
[SPRING] response.getStatus ()를 호출하는 동안 NoSuchMethodError 발생 (0) | 2019.05.19 |
[SPRING] 스프링 보안에서 @Secured 메소드 보안 어노테이션을 사용할 수 없다. (0) | 2019.05.19 |
[SPRING] Jboss No Spring WebApplicationInitializer 유형이 클래스 경로에서 감지되었습니다. (0) | 2019.05.19 |
[SPRING] grails에서 일대 다 관계를위한 동적 폼의 매개 변수 처리 (0) | 2019.05.19 |