JAX-WS:在另一个类注释中使用方法中的参数

时间:2012-03-21 13:10:31

标签: java web-services jax-ws

我正在为工作创建一个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

1 个答案:

答案 0 :(得分:1)

您的类路径指向目标/类。 Maven会将当前模块的所有编译类放在该文件夹中。这就解释了为什么wsgen只在本地模块中找到该类。有jax-ws maven plugin将为您设置类路径。这将是我脑海中最简单的方法。基本上你想要的是......

wsgen -keep -cp target/classes:dependency1.jar:dependency2.jar:etc. -s src/main/java -d target/classes com.mine.WebServiceImpl