我正在尝试为 Web 服务生成 WSDL,但出现此错误:
Note: ap round: 2
Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:153)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:83)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:244)
at com.sun.tools.internal.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:229)
at com.sun.tools.internal.ws.wscompile.WsgenTool.run(WsgenTool.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:105)
at com.sun.tools.internal.ws.WsGen.main(WsGen.java:41)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
this problem is related to the following location:
at java.lang.StackTraceElement
at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
at java.lang.Throwable
at java.lang.Exception
at java.sql.SQLException
at private java.sql.SQLException wsdb.jaxws.SQLExceptionBean.nextException
at wsdb.jaxws.SQLExceptionBean
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:140)
... 10 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
this problem is related to the following location:
at java.lang.StackTraceElement
at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
at java.lang.Throwable
at java.lang.Exception
at java.sql.SQLException
at private java.sql.SQLException wsdb.jaxws.SQLExceptionBean.nextException
at wsdb.jaxws.SQLExceptionBean
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:277)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:95)
at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:97)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:148)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:140)
... 12 more
我在互联网上看到了一些关于此问题的讨论,从为所有类构建构造函数开始,直到创建另一个 xml 规范。事实是,这个问题没有真正的答案,或者我测试的解决方案不起作用。
我在这里阅读了有关此问题的讨论,但它尚未终止,我不知道如何解决。如果有人对此有线索,我非常感激能告诉我正确的方向以避免这种情况。
我在 JDK 6 中使用 Debian Squezze、Java 1.6_20、JAX-WS JAX-WS RI 2.1.6 和 wsgen 来生成 wsdl。它正确执行的第一步是生成包含 bean 类的 jaxws 目录。
I am trying to generate my WSDL for webservices but I get this error:
Note: ap round: 2
Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:153)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:83)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:244)
at com.sun.tools.internal.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:229)
at com.sun.tools.internal.ws.wscompile.WsgenTool.run(WsgenTool.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:105)
at com.sun.tools.internal.ws.WsGen.main(WsGen.java:41)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
this problem is related to the following location:
at java.lang.StackTraceElement
at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
at java.lang.Throwable
at java.lang.Exception
at java.sql.SQLException
at private java.sql.SQLException wsdb.jaxws.SQLExceptionBean.nextException
at wsdb.jaxws.SQLExceptionBean
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:140)
... 10 more
Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.lang.StackTraceElement does not have a no-arg default constructor.
this problem is related to the following location:
at java.lang.StackTraceElement
at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()
at java.lang.Throwable
at java.lang.Exception
at java.sql.SQLException
at private java.sql.SQLException wsdb.jaxws.SQLExceptionBean.nextException
at wsdb.jaxws.SQLExceptionBean
at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:436)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:277)
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1100)
at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:143)
at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:95)
at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:97)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:148)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:140)
... 12 more
I saw a few discusion in internet about this begin with build a constructor for all classes until create another xml specification. The truth is there is no a real answer for this or the solutions that I test doesnt work any.
I read a discussion here about this problem but it was unterminated and I dont know how to resolve. If somebody has a cluee about this I so appreciated to addrees me into rigth direction to avoid this.
I am using Debian Squezze, Java 1.6_20, JAX-WS JAX-WS RI 2.1.6 in JDK 6 and wsgen to generate the wsdl. The first step it did correct, generate the jaxws directory with bean classes.
发布评论
评论(8)
Throwable
对象(意味着异常和错误)无法直接传输,因为它们无法序列化为 XML(StackTraceElement
没有无参数构造函数,这是 JAXB 所必需的)。为此,您必须使用 SOAP 错误。请参阅此问题。它向您指出应将其放在异常类上的
@WebFault
注释。 (也可能检查 这个和此)Throwable
objects (that means exceptions and errors) can't be transferred directly, because they can't be serialized to XML (theStackTraceElement
doesn't have a no-arg constructor, which is required by JAXB).You have to use SOAP faults for that. See this question. It points you to the
@WebFault
annotation which you should put on your exception class. (Also probably check this and this)Domenic D. 的正确答案对我有用,但我想对其进行扩展。
我的 Maven 项目使用 JDK 6 构建得很好,但是当我切换到使用 JDK 1.7 作为默认值时,构建失败了。通过添加带有版本的显式 jaxb-impl 依赖项,它起作用了,例如:
关于版本:此错误列于 https://java.net/jira/browse/JAXB-814。已修复版本 2.2.4u2、2.2.5、2.3
Domenic D. had the right answer that worked for me, but I would like to expand on it.
My Maven project built just fine with JDK 6, but when I switched to be using JDK 1.7 as my default, the build broke. By adding an explicit jaxb-impl dependency w/ version, it worked, such as:
Regarding the version: This bug is listed at https://java.net/jira/browse/JAXB-814. It's fixed for versions 2.2.4u2, 2.2.5, 2.3
我通过将 jaxb-impl 版本从 2.1.9 修复到 2.2.6 解决了这个问题
现在效果很好
I have resolved this issue by fixing the jaxb-impl version from 2.1.9 to 2.2.6
and it works fine now
看起来您声明的 API 的一部分包含一个类型,该类型使用 StackTraceElement[ ] 类型的内部字段扩展了类型。
由于 StackTraceElement 没有零参数构造函数,因此 JAXB 无法反序列化此类的实例。
尝试从 SQLExceptionBean 中删除 nextException 字段,或从服务 API 中删除 SQLExceptionBean 类型的参数。
It looks like a part of your declared API includes a type that extends a type with an internal field of type StackTraceElement[ ].
Because StackTraceElement has no zero-argument constructor, JAXB cannot de-serialize instances of this class .
Try removing the nextException field from SQLExceptionBean, or removing parameters of type SQLExceptionBean from your service APIs.
请注意,您不必创建自定义异常。您只需在生成类时使用正确版本的 JAXB 即可。例如:
Note, that you don't have to create a custom Exception. You just ned to use the right version of JAXB when you are generating your classes. For example:
众所周知,由于 StackTrace 没有默认构造函数,因此 JAXB 无法对任何 Exception/Throwable 类进行编组。您可以做的是创建自己的 Exception 类,该类扩展自示例中的 WebServiceException。在您的类中,重写将使用 StackTrace 的方法并向其添加
@XmlTransient
注释。只要您使用 JAXB 2.2.4u2+,Marshaller 就会遵守自定义类中的@XmlTrasient
注释。更多详细信息请访问 http://java.net/jira/browse/JAXB-814 概述了
@XmlTransient
在子类上不能很好地工作的缺陷。下面是一个可以正确编组的示例类:
如果您使用 Maven,则需要此依赖项:
It is known that any Exception/Throwable class can not be marshalled by JAXB due to the fact that StackTrace does not have a default constructor. What you can do is create your own Exception class that extends from say in your example, WebServiceException. In your class, override the methods that would use StackTrace and add the
@XmlTransient
annotation to them. As long as you are using JAXB 2.2.4u2+ the Marshaller will obey the@XmlTrasient
annotation in your custom class.Additional detail is available at http://java.net/jira/browse/JAXB-814 that outlines the defect where
@XmlTransient
didn't work well on subclasses.Below is a sample class that will marshall properly:
If you use Maven, you'll need this dependency:
我也有这个问题!
一模一样!
看到这个错误,
我检查了我的代码,并检查了原因是
Web 方法不应该抛出异常,删除将简单地解决这个问题,如果你坚持这样做,请按照@Bozho 的第一个答案进行操作。
I had this problem too!
EXACTLY the same one!
SEE THIS ERROR,
I went through my code,and checked out the reason is
A web method should not throw a Exception,remove will solve this problem simplely,if u insist to do that,follow the first answer by @Bozho .
我通过在界面顶部添加 SOAPBinding 解决了这个问题:
I solved this issue by adding a SOAPBinding on top of my interface: