博主自学springboot,跟着书本猛敲,书本springboot版本1,博主不信邪,硬刚2…于是中间出现各种莫名奇妙bug,本次这个bug可谓是巨坑,这里讲述调bug的方法,嫌字多的小伙伴直接文章末尾,解决方案在那里
ConfigServletWebServerApplicationContext : Exception encountered during context
initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
‘defaultValidator’ defined in class path resource
[org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Bean
instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.validation.beanvalidation.LocalValidatorFactoryBean]: Factory method
‘defaultValidator’ threw exception; nested exception is java.lang.NoClassDefFoundError:
javax/el/ELManager
加粗部分关键字中javax/el/ELManager可能不同,但解决方案都大同小异
看以上日志,应该是验证器出现了冲突.这里直接Debug:ELManager源码
第一步:打Exception断点 NoClassDefFoundError 定位问题如下
**断点定位:**查看该段代码j版本为:hibernate-validator\6.0.18.Final
**代码追踪:**追踪上述代码接口并往下调,发现这一部分相同的方法…
巨坑,对应版本为hibernate-validator\5.3.6.Final
博主初学,本次debug应该是项目6.0.18.Final这个版本代码覆盖了5.3.6.Final这部分代码引起,否则debug不会停留方法之上,具体原因不详
查看maven包情况发现冲突
查看项目maven调用树发现问题:里层module项目maven
最外层项目的maven…hibernate隐藏在pom里面,不仔细看不出来,对初学者来讲,真的是巨坑,博主硬撸1小时发现的…
**解决方案:**找到原因之后就很简单了,改掉这个坑爹的版本,我也不知道为啥6不行,反正debug出来是这样就暂时先这样吧
javax/el/ELManager有些小伙伴可能不一样,但解决思路大同小异,本次调bug就记录到这里,欢迎随时提供各种bug!!