gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 15:28:59 38 4
gpt4 key购买 nike

我正在为工作创建一个网络服务。我将其分解为 3 个独立的 Maven 项目:

  • SOA(存储 Web 方法中使用的请求和响应对象)
  • 服务(存储实际进行数据处理的类)
  • WebServices(这存储端点接口(interface)和生成的 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

最佳答案

您的类路径指向目标/类。 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

关于java - JAX-WS:在另一个类注释的方法中使用参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9805301/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com