当使用 WSDL-first 方法生成 java 存根时,有没有办法让异常扩展 RuntimeException 而不是 Exception?
使用 WSDL 优先方法时,有没有办法强制 JAXB 生成扩展 java.lang.RuntimeException 而不是 Exceptions 的异常?
我正在为我的 Java Web 服务项目使用 WSDL 优先方法。存根是使用 CXF 的“wsdl2java”Maven 插件生成的,该插件由 JAXB 驱动。它能够从我的 WSDL 生成存根,包括根据我的 WSDL 中定义的错误生成大约 150 个不同的异常类。然而,所有这些异常都扩展了 java.lang.Exception。对于这个特定的项目,我更喜欢这些异常扩展 java.lang.RuntimeException。
它看起来类似于
Is there a way to force JAXB to generate exceptions which extend java.lang.RuntimeException instead of Exceptions when using a WSDL-first approach?
I'm using a WSDL-first approach for my Java web services project. The stubs are generated with CXF's "wsdl2java" Maven plugin, which is driven by JAXB. It's able to generate stubs from my WSDL, including generating ~150 different exception classes based on the faults defined in my WSDL. However, all of these exceptions extend java.lang.Exception. For this particular project, it's my preference that these exceptions extend java.lang.RuntimeException.
It seems like something similar to the <javaType> annotation might work, but I'm digging through the spec and I haven't found anything yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前没有办法。如果您想提交一个补丁,向 wsdl2java 工具添加一个类似 -exceptionSuper=.... 的标志,我们绝对可以考虑它。如果您查看 tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java 中的 CXF 源代码,您可以看到我们在哪里尝试并确定要使用的超类。在我们的上下文中拉出一个标志是相当简单的。
There isn't a way right now. If you want to submit a patch that would add a flag like -exceptionSuper=.... to the wsdl2java tool, we could definitely consider it. If you look in the CXF source in tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/generators/FaultGenerator.java you can see where we try and determine a superclass to use. Pulling a flag our of the context there would be fairly straight forward.