說明
詳細錯誤日志:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.validator.internal.engine.ConfigurationImpl
at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:33)
at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276)
at org.springframework.boot.validation.MessageInterpolatorFactory.getObject(MessageInterpolatorFactory.java:53)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor$ValidatedLocalValidatorFactoryBean.<init>(ConfigurationPropertiesBindingPostProcessor.java:411)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.getValidator(ConfigurationPropertiesBindingPostProcessor.java:368)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.determineValidator(ConfigurationPropertiesBindingPostProcessor.java:352)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:314)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
本來這種NoClassDefFoundError、NullPointerException之類的異常都沒有任何解決問題的價值,更沒有必要單獨寫一篇博客來介紹這個問題;但是確實還是想吐槽一下~
問題來源
本工程采用了maven構(gòu)建,查看maven依賴樹的時候發(fā)現(xiàn)很多l(xiāng)ogging沖突,自然而然的利用<exclusion>把不必要的依賴項給去除掉,所有就有了這么一段配置:
<exclusion>
<groupId>jboss-logging</groupId>
<artifactId>org.jboss.logging</artifactId>
</exclusion>
加上我的hibernate-validator的版本是5.3.5.final,下意識的解決方法就是換個4.3.5版本的包解決就夠了。確實是,換個版本就完美解決了.但是我還是想探個究竟,看是什么妖魔在作怪?。lasspath下也有這個類ConfigurationImpl,但就是創(chuàng)建對象失敗!
下面開始定位
jboss.logging下就這么幾個類:

image.png
莫非ConfigurationImpl強依賴了其中的某個Log?,而不是slf4j/log4j/logback之類的,哪怕你用common-logging也不至于報創(chuàng)建對象失敗。果不其然,請看:

image.png
鏈進去看一下:

image.png
瞬間有一種想打人的沖動,在hibernate-validator一個公共組件里竟然加入自己的日志模板!不得不佩服大佬們的做法~ 不過問題解決就好了!
總結(jié)
遇到這個問題,沒有立馬反應過來,還是花了10來分鐘查看問題。說明自己還有待提升,至少從日志的設(shè)計層面又加深了一層認識。