闪酷跑路网

一行行枯燥的代码,却描绘出人生的点点滴滴

您现在的位置是:首页>_J2EE

按照教程搭建了一个CXF的WebService服务,但是发布不成功。该怎么解决

发布时间:2018-11-16浏览(3625)

    按照教程搭建了一个CXF的WebService服务,但是发布不成功。
    例子很简单,就3个文件:
    HelloWorld.java 接口类
    Java code
    package ws.cxf;
    import javax.jws.WebService; 
    import javax.jws.WebParam;
    
    @WebService
    public interface HellpWorld {
        String SayHi(@WebParam(name = "text") String text);
    }
    


    HelloWorldImpl.java 实现接口类
    Java code
    package ws.cxf;
    import javax.jws.WebService;
    
    @WebService
    (    endpointInterface="ws.cxf.HelloWorld",//端点接口名称
         serviceName="HelloWorld")//服务名称
    
    public class HelloWorldImpl implements HellpWorld {
    
        public String SayHi(String text) {
            // TODO 自动生成方法存根
            return "Hello" + text;
        }
    }
    


    HelloWorldApp.java 发布程序
    Java code
    package ws.cxf;
    import javax.xml.ws.Endpoint;
    
    public class HelloWorldApp {
        public static void main(String[] args) {
            // TODO 自动生成方法存根
                System.out.println("Starting Server...");
                HelloWorldImpl implementor=new HelloWorldImpl();
                String url="http://localhost:9000/HelloWorld";
                Endpoint.publish(url, implementor);
                System.out.println("Server Started.");
        }
    }
    



    完成后在tomcat中运行,出现的错误如下:
    Exception in thread "main" javax.xml.ws.WebServiceException: Could not load Webservice SEI
    at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialize(JaxWsImplementorInfo.java:276)
    at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.<init>(JaxWsImplementorInfo.java:57)
    at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:289)
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:259)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:209)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:84)
    at javax.xml.ws.Endpoint.publish(Endpoint.java:47)
    at ws.cxf.HelloWorldApp.main(HelloWorldApp.java:26)
    Caused by: java.lang.ClassNotFoundException: ws.cxf.HelloWorld
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass2(ClassLoaderUtils.java:236)
    at org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass(ClassLoaderUtils.java:222)
    at org.apache.cxf.jaxws.support.JaxWsImplementorInfo.initialize(JaxWsImplementorInfo.java:274)
    ... 7 more

    刚接触webservice,请问为什么会有ClassNotFoundException异常?教程上能顺利通过呢。

    等待大侠。。。


    ------解决方案--------------------
    HelloWorld
    HellpWorld 

    你睁大眼睛看看!
    ------解决方案--------------------
    接分
    ------解决方案--------------------