在eclipse中使用cxf发布restful接口运行正常
打成jar包就报错
org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:215)
at com.tls.main.Main.start(Main.java:42)
at com.tls.main.Main.main(Main.java:20)
Caused by: org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://cxf.apache.org/transports/http.
at org.apache.cxf.bus.managers.DestinationFactoryManagerImpl.getDestinationFactory(DestinationFactoryManagerImpl.java:122)
at org.apache.cxf.endpoint.ServerImpl.initDestination(ServerImpl.java:79)
at org.apache.cxf.endpoint.ServerImpl.<init>(ServerImpl.java:63)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:170)
... 2 more
解决办法:
用压缩软件打开jar,找到\META-INF\cxf\bus-extensions.txt
将你maven导入的cxf-rt-transports-http-jetty.jar和cxf-rt-transports-http.jar
把jar里面\META-INF\cxf\bus-extensions.txt内容拷贝到你打包的jar中
注意里面的回车可能是linux下的回车
不同版本的cxf,bus-extensions.txt里面的内容可能不一样
我用的是3.1.4
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.1.4</version>
</dependency>
我的bus-extensions.txt文件内容
org.apache.cxf.bus.managers.PhaseManagerImpl:org.apache.cxf.phase.PhaseManager:true
org.apache.cxf.bus.managers.WorkQueueManagerImpl:org.apache.cxf.workqueue.WorkQueueManager:true
org.apache.cxf.bus.managers.CXFBusLifeCycleManager:org.apache.cxf.buslifecycle.BusLifeCycleManager:true
org.apache.cxf.bus.managers.ServerRegistryImpl:org.apache.cxf.endpoint.ServerRegistry:true
org.apache.cxf.bus.managers.EndpointResolverRegistryImpl:org.apache.cxf.endpoint.EndpointResolverRegistry:true
org.apache.cxf.bus.managers.HeaderManagerImpl:org.apache.cxf.headers.HeaderManager:true
org.apache.cxf.service.factory.FactoryBeanListenerManager::true
org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl:org.apache.cxf.endpoint.ServerLifeCycleManager:true
org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl:org.apache.cxf.endpoint.ClientLifeCycleManager:true
org.apache.cxf.bus.resource.ResourceManagerImpl:org.apache.cxf.resource.ResourceManager:true
org.apache.cxf.catalog.OASISCatalogManager:org.apache.cxf.catalog.OASISCatalogManager:true
org.apache.cxf.jaxrs.JAXRSBindingFactory::true
org.apache.cxf.transport.http_jetty.JettyDestinationFactory::true
org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory::true
org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProviderFactory:org.apache.cxf.transport.http.ContinuationProviderFactory:true
org.apache.cxf.transport.http.HTTPTransportFactory::true
org.apache.cxf.transport.http.HTTPWSDLExtensionLoader::true:true
org.apache.cxf.transport.http.policy.HTTPClientAssertionBuilder::true:true
org.apache.cxf.transport.http.policy.HTTPServerAssertionBuilder::true:true
org.apache.cxf.transport.http.policy.NoOpPolicyInterceptorProvider::true:true