记一次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版本。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值