Fork me on GitHub

spring4 +cxf 排错

##排查依赖错误
由于项目用到cxf 需要调用第三方的接口,需要写一个客户端。这个貌似没啥问题,记得之前写过的cxf 现在好久不用了,apache的官网已经更新到了3.1.7 。
自从用maven以来还真很少遇到过冲突,但是群里大婶说的一句话很好,maven已经较少了依赖关系的冲突,但是不代表就不存在。
项目有用gradle的,也有用maven的。
首先你的jvm可以加上参数 -XX:+TraceClassLoading 这个主要是看你的classtrace的。
mvn dependency:tree 和 gradle的 dependencies 命令很重要。
主要还是看报错控制台的信息,我的错误为 java.lang.NoSuchFileldError : REFLECTION
这就很明显了是冲突,之后看具体的出错的 class —> RuntimeModelBuilder

compile (“com.sun.jersey:jersey-json:$jerseyVersion”){
exclude(module : ‘jaxb-impl’)
}
compile(‘org.apache.cxf:cxf-rt-frontend-jaxws:3.1.7’) {
exclude(module : ‘jaxb-impl’)
exclude(module : ‘jaxb-core’)
}

com.alibaba
dubbo-registry-zookeeper
2.5.4


javax.xml
jaxb-impl

这三个地方用到了!
另外还有

http://stackoverflow.com/questions/25765238/java-lang-nosuchfielderror-reflection

You have a conflict between the cxf-rt-frontend-jaxws and cxf-common-utilities libraries. Both of these provide as their dependencies com.sun.xml.bind which is the cause of your problem. So you should either exclude com.sun.xml.bind:jaxb-impl from cxf-common-utilities or remove your dependency on cxf-common-utilities.

exclude(module : ‘jaxb-impl’)
exclude(module : ‘jaxb-core’) 这里有一个com.sun.xml.bind.v2.model/impl 中有一个什么类具体不清楚和jaxb-impl中有一个类重名也就是冲突。最后才找到原来就是它惹的祸!
共勉の
以后大家用cxf的时候小心,搞了2个多小时。和大家分享下!

本文欢迎转载,但是希望注明出处并给出原文链接。 如果你有任何疑问,欢迎在下方评论区留言,我会尽快答复。 如果你喜欢或者不喜欢这篇文章,欢迎你发邮件到 alonecong@126.com 告诉我你的想法,你的建议对我非常重要。

------ 本文结束感谢您的阅读! ------
0%