报错
20:45:16.837 [main] DEBUG org.apache.cxf.resource.DefaultResourceManager - resolving resource <org.apache.cxf.wsdl11.WSDLManagerImpl/bus> type <interface org.apache.cxf.Bus>
20:45:16.837 [main] DEBUG org.apache.cxf.resource.DefaultResourceManager - resolving resource <null> type <interface org.apache.cxf.Bus>
20:45:16.932 [main] DEBUG org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory - Creating Jetty HTTP Server Engine for port 8000.
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/server/SessionManager
at org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory.getOrCreate(JettyHTTPServerEngineFactory.java:116)
at org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory.createJettyHTTPServerEngine(JettyHTTPServerEngineFactory.java:268)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.retrieveEngine(JettyHTTPDestination.java:121)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.finalizeConfig(JettyHTTPDestination.java:154)
at org.apache.cxf.transport.http.HTTPTransportFactory.getDestination(HTTPTransportFactory.java:281)
at org.apache.cxf.binding.soap.SoapTransportFactory.getDestination(SoapTransportFactory.java:131)
at org.apache.cxf.endpoint.ServerImpl.initDestination(ServerImpl.java:84)
at org.apache.cxf.endpoint.ServerImpl.<init>(ServerImpl.java:63)
at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:170)
at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
at com.suiwei.webservice.Test.main(Test.java:16)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.SessionManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 11 more
Process finished with exit code 1
依赖
发布服务代码,运行该代码,控制台爆出了如上错误
public class Test {
public static void main(String[] args){
//发布服务的工厂
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
//设置服务地址
factory.setAddress("http://localhost:8000/ws/hello");
//设置服务类
factory.setServiceBean(new HelloServiceImpl());
//发布服务
factory.create();
System.out.println("发布成功");
}
}
服务代码
public class HelloServiceImpl implements HelloService {
public String sayHello(String name){
return name+"-success!";
}
}
服务接口
import javax.jws.WebService;
/**
* 对外发布服务的接口@WebService标识*/
@WebService
public interface HelloService {
/**
* 对外发布服务的接口的方法
*/
public String sayHello(String name);
}
经过我的测试,你应该是引错了依赖,使用如下依赖可以正常运行你的代码: