报错:
2018-05-03 10:35:20 377 ERROR org.apache.juli.logging.DirectJDKLog.log:181 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.apache.cxf.jaxrs.provider.ProviderFactory] with root cause
java.lang.NoClassDefFoundError: Could not initialize class org.apache.cxf.jaxrs.provider.ProviderFactory
at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.setupFactory(AbstractJAXRSFactoryBean.java:324) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.initClient(JAXRSClientFactoryBean.java:313) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWebClient(JAXRSClientFactoryBean.java:188) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.WebClient.create(WebClient.java:139) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.WebClient.create(WebClient.java:112) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
或者
2018-05-03 11:12:02 584 ERROR org.apache.juli.logging.DirectJDKLog.log:181 - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.isCglibProxyClass(Ljava/lang/Class;)Z] with root cause
java.lang.NoSuchMethodError: org.springframework.aop.support.AopUtils.isCglibProxyClass(Ljava/lang/Class;)Z
at org.apache.cxf.common.util.SpringAopClassHelper.getRealClassInternal(SpringAopClassHelper.java:85) ~[cxf-common-utilities-2.3.11.jar:2.3.11]
at org.apache.cxf.common.util.ClassHelper.getRealClass(ClassHelper.java:55) ~[cxf-common-utilities-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.provider.ProviderFactory.setProviders(ProviderFactory.java:394) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.provider.ProviderFactory.<clinit>(ProviderFactory.java:72) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.setupFactory(AbstractJAXRSFactoryBean.java:324) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.initClient(JAXRSClientFactoryBean.java:313) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWebClient(JAXRSClientFactoryBean.java:188) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.WebClient.create(WebClient.java:139) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
at org.apache.cxf.jaxrs.client.WebClient.create(WebClient.java:112) ~[cxf-rt-frontend-jaxrs-2.3.11.jar:2.3.11]
原因:
是由spring4.x和cxf2.x的版本不兼容导致的。 在Spring 4.x以上,废弃了setFactoryBean方法,而CXF 2.*采用的是调用Spring的这个方法进行Bean的设置。
解决:将cxf版本换成3.2.4就可以了