记一次Springboot应用启动报错(jackson和springboot的兼容问题)

**

背景:在IDEA中可以部署和启动的springboot应用在打成jar包后启动

**
在IDEA中可以部署和启动的springboot应用在打成jar包后无法启动: Unable to start embedded Tomcat
按照以往处理报错的经验,找问题先从底部开始,一步步看,根源一定是最后一个抛出的异常导致,最后报错详细如下:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        ... 62 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/exc/InvalidDefinitionException
        at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:76) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        at org.springframework.web.filter.FormContentFilter.<init>(FormContentFilter.java:60) ~[spring-web-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        at org.springframework.boot.web.servlet.filter.OrderedFormContentFilter.<init>(OrderedFormContentFilter.java:29) ~[spring-boot-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.formContentFilter(WebMvcAutoConfiguration.java:166) ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$b8b9dc30.CGLIB$formContentFilter$0(<generated>) ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$b8b9dc30$$FastClassBySpringCGLIB$$8b99cef0.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$$EnhancerBySpringCGLIB$$b8b9dc30.formContentFilter(<generated>) ~[spring-boot-autoconfigure-2.1.6.RELEASE.jar!/:2.1.6.RELEASE]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_121]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_121]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
        ... 63 common frames omitted

最后一个错误是一个类无法找到的错误,仔细看可以发现这个是一个springboot的内部包抛出的异常,异常的指向却是一个jackson的包内异常,说明是一个引用错误依赖,跟踪源码发现却是存在依赖冲突:

Factory method 'formContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError:
 com/fasterxml/jackson/databind/exc/InvalidDefinitionException

解决方案:
1、删除jackson的包,替换其他类json框架。
2、升级jackson的版本,我的冲突版本是springboot2.1.6和jackson2.7.4版本。

你可能感兴趣的:(springboot)