9

I generate server/client from my wsdl/xsd's using the cxf-codegen-plugin for Maven. All the types created have default no-arg-constructors, which makes them a pain to work with.

Is there any way to make Apache CXF generate a full constructor aswell, with all the members of the class as arguments?

4

1 回答 1

7

这个插件只是 xjc 的一个精美包装器。

有两个 xjc 插件可以解决您的问题空间:

  • 正是您正在寻找的价值构造器。
  • Fluent-api并不完全符合您的要求,但许多人更喜欢 fluent api 来赋值构造函数。

您需要添加所需的依赖项,然后配置插件以在 xjc 中启用这些插件,例如

<plugin>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-codegen-plugin</artifactId>
  <configuration>
    <defaultOptions>
      <extraargs>
        <extraarg>-xjc-Xvalue-constructor</extraarg>
      </extraargs>
    </defaultOptions>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-value-constructor</artifactId>
      <version>3.0</version>
    </dependency>
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics</artifactId>
      <version>0.6.4</version>
    </dependency>
  </dependencies>
</plugin>

注意:上面将其设为所有执行的默认值,如果您只想为特定执行启用这些选项,则只需将该<configuration>位添加到该特定执行中。

于 2012-08-21T08:17:15.457 回答