如何防止 JAXBElement从在 CXF Web 服务客户端中生成?

如何防止 JAXBElement<String>从在 CXF Web 服务客户端中生成?

问题描述:

我正在尝试使用 CXF 创建一个 Web 服务客户端来使用 WCF Web 服务.当我使用 wsdl2java 时,它会生成 JAXBElement 类型而不是 String 类型的对象.

I'm trying to create a web service client using CXF to consume a WCF web service. When I use wsdl2java it generates objects with JAXBElement types instead of String.

我了解到使用 jaxb bindings.xml 文件设置 generateElementProperty="false" 以尝试解决问题,但我使用的 Web 服务包含 7 个导入的架构.

I read about using a jaxb bindings.xml file to set generateElementProperty="false" to try to fix the problem, but the web service I'm consuming contains 7 imported schemas.

如何在所有七个模式上指定 generateElementProperty="false",或者有没有办法将其应用于所有模式?

How can I specify the generateElementProperty="false" on all seven schemas, or is there a way to apply it to all schemas?

你必须创建一个如下的绑定文件,这将被全局应用并用作wsdl2java - b "bindings.txt" "wsdl"

You have to create a binding file as below, this will get applied globally and use it as wsdl2java - b "bindings.txt" "wsdl"

<jaxb:bindings version="2.1" 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
   <jaxb:globalBindings generateElementProperty="false"/> 
</jaxb:bindings>