【发布时间】:2012-03-21 13:10:31
【问题描述】:
我正在为工作创建一个 Web 服务。我将其分解为 3 个独立的 Maven 项目:
- SOA(存储 Web 方法中使用的请求和响应对象)
- 服务(存储实际处理数据的类)
- WebServices(存储端点接口和生成的 jaxws 文件夹)
在 SOA 项目中,我有一个简单的 POJO,用于将所需的值传递给 web 方法
public class RequestObject {
private String firstName = null;
private String lastName = null;
// Setters and Getters below...
}
然后我尝试在 WebServices 项目中引用这个类。我将 SOA 生成的 JAR 作为依赖项包含在 Maven 中。这确实有效,并且可以正确提取文件。
接口:
@WebService
public interface WebServiceInf {
@WebMethod
@WebResult(name="WebMethodResult")
String createSomething(@WebParam(name="requestObject")RequestObject request);
}
网络服务:
import com.mine.data.RequestObject;
@WebServiceInterface(endpointInterface="com.mine.WebServiceInf")
public class WebServiceImpl implements WebServiceInf {
@Override
public String createSomething(RequestObject request) {
return "I was created!";
}
}
我遇到的问题是当我使用 wsgen 工具时。如果我将 RequestObject 放在 WebService 项目中,它工作正常。但是,一旦我将该类放入 SOA 项目中,它就会引发以下错误:
Problem encountered during annotation processing; see stacktrace below for more information. java.lang.NullPointerException
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.isLegalType(WebServiceVisitor.java:770)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.isLegalParameter(WebServiceVisitor.java:670)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.isLegalMethod(WebServiceVisitor.java:637)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.methodsAreLegal(WebServiceVisitor.java:575)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.isLegalSEI(WebServiceVisitor.java:567)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.shouldProcessWebService(WebServiceVisitor.java:300)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.visitInterfaceDeclaration(WebServiceVisitor.java:94)
at com.sun.tools.apt.mirror.declaration.InterfaceDeclarationImpl.accept(InterfaceDeclarationImpl.java:32)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.inspectEndpointInterface(WebServiceVisitor.java:395)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceVisitor.visitClassDeclaration(WebServiceVisitor.java:128)
at com.sun.tools.apt.mirror.declaration.ClassDeclarationImpl.accept(ClassDeclarationImpl.java:95)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAP.buildModel(WebServiceAP.java:315)
at com.sun.tools.internal.ws.processor.modeler.annotation.WebServiceAP.process(WebServiceAP.java:256)
at com.sun.mirror.apt.AnnotationProcessors$CompositeAnnotationProcessor.process(AnnotationProcessors.java:60)
at com.sun.tools.apt.comp.Apt.main(Apt.java:454)
at com.sun.tools.apt.main.JavaCompiler.compile(JavaCompiler.java:258)
at com.sun.tools.apt.main.Main.compile(Main.java:1102)
at com.sun.tools.apt.main.Main.compile(Main.java:964)
at com.sun.tools.apt.Main.processing(Main.java:95)
at com.sun.tools.apt.Main.process(Main.java:85)
at com.sun.tools.apt.Main.process(Main.java:67)
at com.sun.tools.internal.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:204)
at com.sun.tools.internal.ws.wscompile.WsgenTool.run(WsgenTool.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:105)
at com.sun.tools.internal.ws.WsGen.main(WsGen.java:41) error: compilation failed, errors should have been reported
所以这看起来我需要一个特定的注释来告诉 WebService 项目 RequestObject 在另一个项目/JAR 中。
我会使用什么注释来做到这一点?非常感谢您的帮助!
更新
这就是我对 wsgen 的称呼。我正在从 WebServices 根文件夹
执行此命令wsgen -keep -cp target/classes/ -s src/main/java -d target/classes/ com.mine.WebServiceImpl
【问题讨论】:
-
我感觉这可能与@WebParam 注释有关,但我不确定
-
SOA项目是WebService项目的依赖吗?
-
@Pace:是的。在 Maven POM 中,我将 SOA 项目作为依赖项包含在其中。
-
我以前做过,所以应该可以。但是,我也很确定该错误表明 wsgen 在编译时遇到了不在类路径上的类。您是否使用 SOA 依赖项的默认范围?
-
我将用我如何运行 wsgen 来更新这个问题,也许这会有所帮助。我打赌这是现在的问题,但现在确定如何让 wsgen 指向两个类路径。
标签: java web-services jax-ws