问题描述
对于Web服务,我们通常使用maven-jaxb2插件生成java bean,并在Spring中使用JAXB2编组。我想知道如何处理最好在WSDL / XSD中声明的(SOAP-)故障。在应用程序中,我想使用编组的错误的Java异常。这可能吗?我没有找到一种方法来生成maven-jaxb2-plugin的源代码生成异常。谢谢!更新:我想使用spring-ws。但是我想主要的问题是如何用jaxb2源代码生成java异常。
Jaxb2插件从XSD中生成bean 。您可以使用 jaxws-maven-plugin
instad maven-jaxb2-plugin
。
尝试使用这个:
<插件>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> jaxws-maven-plugin< / artifactId>
<执行>
< execution>
< id> generate-from-wsdl<
< goals>
< goal> wsimport< /
< / goals>
< / execution>
< / executions>
< configuration>
< wsdlDirectory> src / main / resources / wsdl /< / wsdlDirectory>
< keep> true< / keep>
< sourceDestDir> target / generated-sources / wsimport< / sourceDestDir>
< / configuration>
< / plugin>
只需调用命令 mvn clean install
您将在两个软件包中的 target / generated-sources / wsimport
中找到生成的资源:
- 类型 - 与jaxb相同的生成的java bean
- wsdl - 从wsdl生成的类,异常,接口
For webservices we usually generate java beans with the maven-jaxb2-plugin and use JAXB2 marshalling in Spring. I am wondering how to handle (SOAP-)faults that are declared in the WSDL/XSD best. In the application I would like to use Java exceptions that are marshalled to the faults. Is this possible? I haven't found a way to generate exceptions with the sourcecode generation of the maven-jaxb2-plugin. Thanks!
Update: I'd like to use spring-ws. But I guess the main problem is how to generate java exceptions with jaxb2 source generator.
Jaxb2-plugin generates beans from XSD only. You can use jaxws-maven-plugin
instad of maven-jaxb2-plugin
.
Try using this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-from-wsdl<
<goals>
<goal>wsimport</
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>src/main/resources/wsdl/</wsdlDirectory>
<keep>true</keep>
<sourceDestDir>target/generated-sources/wsimport</sourceDestDir>
</configuration>
</plugin>
Just simply invoke command mvn clean install
, you'll find generated resources in target/generated-sources/wsimport
on two packages:
- types-generated java beans same as from jaxb
- wsdl-classes, exceptions, interfaces generated from wsdl
这篇关于使用JAXB2从XSD /绑定异常生成Java异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!