When using a WSDL-first approach to generate java stubs, is there a way to make exceptions extend RuntimeException instead of Exception?
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.
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.
精彩评论