如何让 wsimport 生成构造函数? [英] How do I make wsimport generate constructors?

查看:73
本文介绍了如何让 wsimport 生成构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wsimport 生成没有参数化构造函数的源代码.因此,如果 bean 有很多属性,则需要手动调用所有 setter:

wsimport generates source code without parameterized constructors. Therefore, if the bean has many properties, one needs to invoke all the setters manually:

Person person = new Person();
person.setName("Alex");

Address address = new Address();
address.setCity("Rome");

person.setAddress(address);

像这样编写代码更易读和方便:

It's much more readable and convenient to just write the code like this:

Person person = new Person("Alex", new Address("Rome"))

那么,有什么方法可以让 wsimport 完成这项工作?(我使用的是 maven wsimport 插件)

So, is there any way to make wsimport do this job? (I'm using maven wsimport plugin)

推荐答案

使用 xjc 工具的 JAXB 值构造器插件.您可以将它与 maven-xjc-plugin 一起使用,如下所示:>

Use the JAXB Value Constructor Plugin for the xjc tool. You can use it with maven-xjc-plugin like this:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xjc-maven-plugin</artifactId>
        <version>1.0-beta-2-SNAPSHOT</version>
        <executions>
          <execution>
            <goals>
              <goal>xjc</goal>
            </goals>
            <configuration>
              <task><![CDATA[
                <xjc schema="src/main/resources/com/acme/services.xsd" package="com.acme">
                   <arg value="-Xvalue-constructor" />
                </xjc>
              ]]></task>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>    

这篇关于如何让 wsimport 生成构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆