问题
在JAX-WS开发中,部署以下服务端点时,
文件:HelloWorld.java
package com.mkyong.ws;
//Service Endpoint Interface
@WebService
public interface HelloWorld{
@WebMethod String getHelloWorldAsString();
}
文件:HelloWorldImpl.java
//Service Implementation
package com.mkyong.ws;
@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
@Override
public String getHelloWorldAsString() {
//...
}
}
它立即命中以下错误消息?
Exception in thread "main" com.sun.xml.internal.ws.model.RuntimeModelerException:
runtime modeler error:
Wrapper class com.mkyong.ws.jaxws.GetHelloWorldAsString is not found.
Have you run APT to generate them?
at com.sun.xml.internal.ws.model.RuntimeModeler.getClass(RuntimeModeler.java:256)
//...
解
服务端点接口未使用任何@SOAPBinding
注释,因此,它将使用默认的文档样式进行发布。 为了便于阅读,您可以按以下方式重写它:
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL)
public interface HelloWorld{
@WebMethod String getHelloWorldAsString();
}
在文档样式中,您需要使用“ wsgen ”工具为服务发布生成所有必需的JAX-WS可移植工件(映射类,wsdl或xsd模式)。
wsgen命令
需要wsgen命令来读取服务端点实现类:
wsgen -keep -cp . com.mkyong.ws.HelloWorldImpl
它在package.jaxws文件夹下为单个getHelloWorldAsString()
方法生成两个类。
- GetHelloWorldAsString.java
- GetHelloWorldAsStringResponse.java
将这些类复制到正确的文件夹,在本例中为“ com.mkyong.ws.jaxws ”。 尝试再次发布。