问题
Is there a way to configure JAXB to so that a generated class implements a specified interface? I'm intending to use JAXB generated classes as DAO's and they should be able implement my DAO interface.
回答1:
The interface injection plugin for XJC lets you do this.
回答2:
Unfortunately, it looks like the interface-injection plugin mentioned in some of the other answers is no longer well supported. In fact, I'm having trouble finding the JAR for download.
Thankfully, the JAXB2 Basics Plugins provides a similar mechanism for adding an interface to the generated JAXB stubs (see the Inheritance plugin).
The JAXB2 Basics Plugins documentation includes instructions for using the plugin with Ant and Maven.
The JAXB2 Basics Plugins provides a number of other utilities which you might also find useful (such as autogeneration of equals, hashCode, and toString methods).
来源:https://stackoverflow.com/questions/2916217/jaxb-generated-classes-implement-interface