资源预览内容
第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
亲,该文档总共7页全部预览完了,如果喜欢就下载吧!
资源描述
最近开发开始学习 Web Service,如果你是大神,请路过!谢谢!遵循前辈大神们的教导 ,内事不决问度娘,外事不决问谷歌(现在谷歌已经不能用了) ,只能问度娘了!上网 一百度,套用周董的一句歌词,霍,霍,霍,霍,这么多的套路(axis,axis2,XFire,CXF 等), 我到底选择哪一个?因为要和 Spring 进行对接,看了一下,CXF 与 Spring 的耦合度最好, 于是就选择了 CXF。上官网下 jar 包,下了最新的 apache-cxf-3.1.4.zip 包。解压出来,看看 里面的最简单的实例,apache-cxf-3.1.4samplesjava_first_jaxws,本着你快乐所以我快乐加 上不要脸的原则,我抄抄抄,改了一下名字,开发环境开发环境 jdk1.6, jdk1.5 没试过,上眼呐! 新建工程 mywbs,导入 jar 包cxf-core-3.1.4.jar jetty-continuation-9.2.11.v20150529.jar jetty-http-9.2.11.v20150529.jar jetty-io-9.2.11.v20150529.jar jetty-server-9.2.11.v20150529.jar jetty-util-9.2.11.v20150529.jar wsdl4j-1.6.3.jar xmlschema-core-2.2.1.jar一、接口类IHelloWorld.java package com.ws.hello;import java.util.List;import javax.jws.WebService;import com.ws.entity.Users;WebServicepublic interface IHelloWorld public String sayHello(String name);public String getUserName(Users user);public List getListUser();二、实现类(说明endpointInterface = “com.ws.hello.IHelloWorld“,IHelloWorld 类加上路径,此处注意类加上路径,此处注意) HelloWorldImpl.javapackage com.ws.hello;import java.util.ArrayList;import java.util.List;import javax.jws.WebService;import com.ws.entity.Users;WebService(endpointInterface = “com.ws.hello.IHelloWorld“,serviceName = “IHelloWorld“, portName=“IHelloWorldPort“)public class HelloWorldImpl implements IHelloWorld Overridepublic String sayHello(String name) return name + “: 您好啊!“; Overridepublic String getUserName(Users user) return user.getName();Overridepublic List getListUser() System.out.println(“getListUser called“);List list = new ArrayList();list.add(new Users(2,“张三“);list.add(new Users(3, “十八罗汉“);list.add(new Users(4,“五王“); return list;三、实体类Users package com.ws.entity;import java.io.Serializable;public class Users implements Serializableprivate static final long serialVersionUID = -5031894017095689998L;private Integer id;private String name;public Integer getId() return id;public void setId(Integer id) this.id = id;public String getName() return name;public void setName(String name) this.name = name;public Users(Integer id, String name) super();this.id = id;this.name = name;public Users() super();Users 类如果不写默认构造方法,将报如下异常: Exception in thread “main“ javax.xml.ws.WebServiceException: Unable to create JAXBContextat com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(Unknown Source)at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(Unknown Source)at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(Unknown Source)at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(Unknown Source)at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(Unknown Source)at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)at com.sun.xml.internal.ws.api.server.WSEndpoint.create(Unknown Source)at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(Unknown Source)at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(Unknown Source)at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(Unknown Source)at javax.xml.ws.Endpoint.publish(Endpoint.java:220)at com.ws.deploy.DeployHelloWorldService.(DeployHelloWorldService.java:14)at com.ws.deploy.DeployHelloWorldService.main(DeployHelloWorldService.java:23)Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptionscom.ws.entity.Users does not have a no-arg default constructor.this problem is related to the following location:at com.ws.entity.Usersat public java.util.List com.ws.hello.jaxws.GetListUserResponse._returnat com.ws.hello.jaxws.GetListUserResponseat java.security.AccessController.doPrivileged(Native Method). 13 moreCaused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions com.ws.entity.Users does not have a no-arg default constructor.this problem is related to the following location:at com.ws.entity.Usersat public java.util.List com.ws.hello.jaxws.GetListUserResponse._returnat com.ws.hello.jaxws.GetListUserResponseat com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(Unknown Source)at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(Unknown Source)at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(Unknown Source)at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(Unknown Source)at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(Unknown Source). 14 more晕了,真是崩溃了,就写了这么几句话!错误代码比正常代码还要多!真是婶婶能忍叔叔 不能忍,虽然英语很烂,连猜带蒙吧,看黑色的一句话,大概似乎是告诉我们Users类中没 有默认的构造方法,果断加上,错误消失!此处应有掌声!鼓掌!四、DeployHelloWorldService.javapackage com.ws.d
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号