错误如下:
九月 21, 2022 6:25:48 下午 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
信息: Creating Service {http://Imp.service.webservice.com/}ServerImpService from class com.webservice.service.Server
Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:193)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at com.webservice.Server.main(Server.java:11)
Caused by: java.io.IOException: Could not find destination factory for transport http://schemas.xmlsoap.org/soap/http
at org.apache.cxf.binding.soap.SoapTransportFactory.getDestination(SoapTransportFactory.java:132)
at org.apache.cxf.endpoint.ServerImpl.initDestination(ServerImpl.java:85)
at org.apache.cxf.endpoint.ServerImpl.<init>(ServerImpl.java:64)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:182)
... 2 more
报这个错位的原因有两个:
原因1:未导入cxf-rt-transports-http-jetty依赖
解决办法:加入依赖
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.4.3</version>
</dependency>
原因2:在发布服务的地址address地址写法不对
例:
package com.webservice;
import com.webservice.service.Imp.ServerImp;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class Server {
public static void main(String[] args) {
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceBean(new ServerImp());
factory.setAddress("127.0.0.1:9999/aa/bb);
factory.create();
System.out.println("服务发布成功,端口:9527");
}
}
不能写 127.0.0.1:9999/aa/bb 而是应该写成 http://127.0.0.1:9999/aa/bb
由于自己的疏忽大意本人就在第二处犯的错