JAXB自动生成的类层次结构 [英] JAXB auto generated classes hierarchy

查看:75
本文介绍了JAXB自动生成的类层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于各种WSDL生成Java代码。对于我们发布的每个新版本的WebService,我们都有一个不同的WSDL,每个版本都有其自己的命名空间。

I'm generating java code based on various WSDL's. We have a different WSDL for every new version of the WebService that we release, each with its own namespace.

通常,从一个发行版到发行版之间的更改通常很小

The thing is that normally the changes are minimal from one release to another, but I want to keep classes divided by namespace.

是否可以配置JAXB,以便自动生成的类实现单个接口/扩展单个类,

Is there a way to configure JAXB so that the auto generated classes implement a single interface/extend a single class, so I can refer to either of them without changing my code?

虚拟示例:

WebService方法: listScripts(ResultSize size);

WebService method: listScripts(ResultSize size);

自动生成的类:


  • com.test.ws1.ResultSize

  • com.test。 ws2.ResultSize

  • com.test.ws1.ResultSize
  • com.test.ws2.ResultSize

两个类完全相同。有没有一种方法可以将它们排列在类层次结构中,从而使我的代码与版本号的更改隔离开?即两个类都实现的 com.test.ResultSize 接口?

Both classes are exactly the same. Is there a way to arrange them in a class hierarchy so my code is isolated from changes in version numbers? i.e. a com.test.ResultSize interface implemented by both classes?

推荐答案

事实证明,我可以使用JAXB2 Basics软件包中提供的插件:

It turned out that I can use a plugin provided in the JAXB2 Basics package:

继承插件

通过该插件,我可以为生成的类指定不同的超类,尽管我不能

With this plugin I can specify different super classes for my generated ones, although I couldn't make the auto generated enums to implement a given interface.

要在Maven中使用它,这很痛苦(我是从WSDL生成类,而不是直接使用JAXB) ),因此我按照此博客

To use it in Maven it was a pain (I'm generating classes from a WSDL, not using JAXB directly), so I switched to an external Ant task as specified in this blog

这篇关于JAXB自动生成的类层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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