標籤:
Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class com.wa.jaxws.SayHello is not found. Have you run APT to generate them? at com.sun.xml.internal.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:256) at com.sun.xml.internal.ws.model.RuntimeModeler.processDocWrappedMethod(RuntimeModeler.java:567) at com.sun.xml.internal.ws.model.RuntimeModeler.processMethod(RuntimeModeler.java:514) at com.sun.xml.internal.ws.model.RuntimeModeler.processClass(RuntimeModeler.java:341) at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:227) at com.sun.xml.internal.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:308) at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:174) at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:420) at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:439) at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:208) at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:138) at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:90) at javax.xml.ws.Endpoint.publish(Endpoint.java:170) at com.wa.ServerTest.main(ServerTest.java:9)
原因
cxf需要jaxws-api-2.1.jar及jaxb-api-2.1.jar的支援。
解決辦法
1. 檢查項目裡是否有上述相關Jar包,如果沒有,將cxf所需的2.1的jar複製一份到jdk目錄下的jre\lib\endorsed檔案夾中。如果endorsed檔案夾不存在,可建立。
2. 項目裡是有上述相關Jar包,還需要在public class XXX類上方加入@SOAPBinding(style = SOAPBinding.Style.RPC);
3. JDK升級到1.6.0.22版本以上;
定義介面方法: @WebServicepublic interface HelloInt { @WebMethod public String sayHello(String name );}定義實作類別:@WebService@SOAPBinding(style = SOAPBinding.Style.RPC)public class HelloImpl implements HelloInt { @Override public String sayHello(String name) { return "hello,"+name; }}測試方法:public class ServerTest { public static void main(String[] args) { String address = "http://192.168.1.100:8989/d01ws/hello"; Endpoint.publish(address,new HelloImpl()); System.out.println("webservice發布成功"); }}
運行程式:
在瀏覽器地址欄輸入:http://192.168.1.100:8989/d01ws/hello?wsdl
可以看到內容,發布成功:
<?xml version="1.0" encoding="UTF-8"?>@namespace html url(http://www.w3.org/1999/xhtml); :root { font:small Verdana; font-weight: bold; padding: 2em; padding-left:4em; } * { display: block; padding-left: 2em; } html|style { display: none; } html|span, html|a { display: inline; padding: 0; font-weight: normal; text-decoration: none; } html|span.block { display: block; } *[html|hidden], span.block[html|hidden] { display: none; } .expand { display: block; } .expand:before { content: ‘+‘; color: red; position: absolute; left: -1em; } .collapse { display: block; } .collapse:before { content: ‘-‘; color: red; position: absolute; left:-1em; }<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.1.1 in JDK 6. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI‘s version is JAX-WS RI 2.1.1 in JDK 6. --><definitions name="HelloImplService" targetNamespace="http://wa.com/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://wa.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><?XML:NAMESPACE PREFIX = [default] http://schemas.xmlsoap.org/wsdl/ NS = "http://schemas.xmlsoap.org/wsdl/" /><types/><message name="sayHello"><part name="arg0" type="xsd:string"/></message><message name="sayHelloResponse"><part name="return" type="xsd:string"/></message><portType name="HelloImpl"><operation name="sayHello" parameterOrder="arg0"><input message="tns:sayHello"/><output message="tns:sayHelloResponse"/></operation></portType><binding name="HelloImplPortBinding" type="tns:HelloImpl"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="sayHello"><soap:operation soapAction=""/><input><soap:body namespace="http://wa.com/" use="literal"/></input><output><soap:body namespace="http://wa.com/" use="literal"/></output></operation></binding><service name="HelloImplService"><port name="HelloImplPort" binding="tns:HelloImplPortBinding"><soap:address location="http://192.168.1.110:8989/d01ws/hello"/></port></service></definitions>
webservice(一) 初涉