最近在研究webservice,利用jdk来实现简单的webservice发布,但是运行时却发生了这样的异常,如下:
Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException: runtime modeler error: Wrapper class webservice.jaxws.SayHi 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 webservice.Test.main(Test.java:8)
最后发现原来是jdk的版本过低,我使用的是jdk1.6.10,而最低要求为1.6.22以上即可,故特此记录下来,谨防再次出错
另外,此种发布方法如下:
第一步:定义接口HelloWorld
package webservice;
import javax.jws.WebService;
@WebService public interface HelloWorld {
String sayHi(String str);
}
第二步:实现类HelloWorldImpl
package webservice;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService(endpointInterface = "webservice.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String str) {
System.out.println("我是webservice");
return "Hello ," + str;
}
public static void main(String[] args) {
Endpoint.publish("http://localhost:8088/hello", new HelloWorldImpl());
}
}
第三步:运行HelloWorldImpl.java main方法
第四步:在浏览器地址栏输入:http://localhost:8088/hello?wsdl
第五步:查看响应xml文件:如成功返回如下: