java JAXB、CXF:没有带有 @XmlElementDecl 元素的 ObjectFactory ......
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5939715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAXB, CXF: There's no ObjectFactory with an @XmlElementDecl for the element ... with
提问by rahul
I'm creating a WSDL first webservice with JAXB and CXF. I do not own the WSDL, so I cannot make changes to it. I'm using ftp://ftp.ihe.net/TF_Implementation_Material/ITI/wsdl/PIXManager.wsdlas my WSDL. I used CXF 2.3.0 to generate Java classes.
我正在使用 JAXB 和 CXF 创建一个 WSDL 第一个 web 服务。我不拥有 WSDL,因此我无法对其进行更改。我使用ftp://ftp.ihe.net/TF_Implementation_Material/ITI/wsdl/PIXManager.wsdl作为我的 WSDL。我使用 CXF 2.3.0 来生成 Java 类。
Java class generation went fine, but when I'm trying to run this in a web application, I get an error
Java 类生成正常,但是当我尝试在 Web 应用程序中运行它时,出现错误
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 17 counts of IllegalAnnotationExceptions
The 17 counts are of the format
17个计数的格式
There's no ObjectFactory with an @XmlElementDecl for the element {urn:hl7-org:v3}assignedDevice.
this problem is related to the following location:
at protected javax.xml.bind.JAXBElement org.hl7.v3.QUQIMT021001UV01AuthorOrPerformer.assignedDevice
When I go to the class mentioned, i.e. QUQIMT021001UV01AuthorOrPerformer and look at the field assignedDevice, I see this
当我去提到的类,即 QUQIMT021001UV01AuthorOrPerformer 并查看字段assignedDevice时,我看到了这个
@XmlElementRef(name = "assignedDevice", namespace = "urn:hl7-org:v3", type = JAXBElement.class)
protected JAXBElement<COCTMT090300UV01AssignedDevice> assignedDevice;
When I look at the ObjectFactory of the package, I see this
当我查看包的 ObjectFactory 时,我看到了这个
private final static QName _COCTMT090303UV01AssignedDeviceAssignedDevice_QNAME = new QName("urn:hl7-org:v3", "assignedDevice");
All my 17 errors are similar. What can I do during my codegen or runtime in order to get my service work?
我所有的 17 个错误都是相似的。我可以在代码生成或运行时做什么才能使我的服务正常工作?
回答by David J. Liszewski
What Java version are you using at run-time? I had a similar issue with OTA schema when running with Java 6. I eliminated the problem by making the following changes to the Maven configuration:
您在运行时使用的是哪个 Java 版本?在使用 Java 6 运行时,我遇到了与 OTA 模式类似的问题。我通过对 Maven 配置进行以下更改来消除该问题:
- Use JAXB impl 2.1.* (instead of 2.2) with
provided
scope, to match JAXB version included in Java 6. - Use JAX-WS 2.1 (instead of 2.2) to match Java 6 and JAXB 2.1.x.
- Add the option
frontEnd
to the Mavencxf-codegen-plugin
plug-in and set it tojaxws21
(or if usingwsdl2java
on command line, use "-fe jaxws21
" option).
- 使用带有
provided
作用域的JAXB impl 2.1.*(而不是 2.2),以匹配 Java 6 中包含的 JAXB 版本。 - 使用 JAX-WS 2.1(而不是 2.2)来匹配 Java 6 和 JAXB 2.1.x。
- 将选项添加
frontEnd
到 Mavencxf-codegen-plugin
插件并将其设置为jaxws21
(或者如果wsdl2java
在命令行上使用,请使用“-fe jaxws21
”选项)。
回答by Martins
When you generate the classes, you also generate a file called jaxb.properties. Make sure this file is accessible to the application at runtime. I had the same problem and it was due to maven packaging: maven will not include in the package resource files (like jaxb.properties) that are below the src/main/java tree unless specifically instructed to do so. I did this using the org.codehaus.mojo:build-helper-maven-plugin with the add-resource goal. Hope this helps
生成类时,还会生成一个名为 jaxb.properties 的文件。确保应用程序在运行时可以访问此文件。我遇到了同样的问题,这是由于 maven 打包造成的:maven 不会包含在 src/main/java 树下的包资源文件(如 jaxb.properties)中,除非特别指示这样做。我使用 org.codehaus.mojo:build-helper-maven-plugin 和 add-resource 目标做到了这一点。希望这可以帮助
回答by Rahul Razdan
I Faced this similar error and the reason was having conflicts between the webservices generated stub java classes.
我遇到了这个类似的错误,原因是 webservices 生成的存根 java 类之间存在冲突。
if above answers does not work , try look for conflicts.
如果以上答案不起作用,请尝试查找冲突。
add one stub at a time and add incrementally.
一次添加一个存根并逐步添加。
hope it helps
希望能帮助到你