外部为类创建 jaxb 注解
因此,通常我在代码中应用 JAXB 注释,如下所示:
package com.example;
@XmlRootElement(name = "Foo", namespace = "example.com")
@XmlType(name = "Foo", namespace = "example.com")
public class Foo {
...
}
Foo 是一个 java 类,用于与 Web 服务通信(通过 Spring/CXF)。上面的注释有助于在 wsdl 中正确生成 XML 模式。
我遇到了无法修改类本身的情况,但我可以为生成架构的代码提供 jaxb 外部绑定文件。请注意,类中存在@XmlRootElement。
如何编写一个等效的绑定文件来完成上述注释的功能?
So, usually I apply JAXB annotations in the code as follows:
package com.example;
@XmlRootElement(name = "Foo", namespace = "example.com")
@XmlType(name = "Foo", namespace = "example.com")
public class Foo {
...
}
Foo is a java class that is used to communicate with web services (via Spring/CXF). The above annotations, help generate the XML Schema in the wsdl appropriately.
I have hit a situation where I can not modify the class itself, but I can provide an jaxb external binding file to the code that generates the schema. Note that the @XmlRootElement exists in the class.
How do I write an equivalent binding file that does what the above annotations do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只需要向生成的类添加
@XmlType(name = "Foo", namespace = "example.com")
注释,您可以使用 JAXB Annotate Plugin。如果您使用 CXF 和 maven,您也可以像这样使用 cxf-codegen-plugin
您还可以使用 maven-jaxb2-plugin:
这是示例绑定文件:
如果您需要修改
@XmlRootElement
同样,只需添加另一个annox:annotate
元素:If you just need to add
@XmlType(name = "Foo", namespace = "example.com")
annotation to the generated class you can use JAXB Annotate Plugin.If you're using CXF and maven you can also you cxf-codegen-plugin somehow like this
You can also use maven-jaxb2-plugin:
Here is sample binding file:
If you need to modify
@XmlRootElement
too, just add another oneannox:annotate
element:注意:我是EclipseLink JAXB (MOXy) 的领导者和 JAXB 的成员(JSR-222)专家组。
JAXB 的 MOXy 实现有一个外部映射文件,您可以使用它来提供元数据。
了解更多信息
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
The MOXy implementation of JAXB has an external mapping file that you can use to provide the metadata.
For More Information