无法创建 JAXBContext 创建我的 wsdl

2022-09-02 08:59:40

我正在尝试为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规范。事实是,对此没有真正的答案,或者我测试的解决方案不起作用。

我在这里读到了关于这个问题的讨论,但它没有被终止,我不知道如何解决。如果有人对此有所了解,我非常感激地将我推向严谨的方向以避免这种情况。

我正在使用 Debian Squezze,Java 1.6_20,JDK 6 和 wsgen 中的 JAX-WS JAX-WS RI 2.1.6 来生成 wsdl。它纠正的第一步是使用bean类生成jaxws目录。


答案 1

Throwable对象(这意味着异常和错误)不能直接传输,因为它们不能序列化为XML(没有JAXB需要的no-arg构造函数)。StackTraceElement

为此,您必须使用 SOAP 错误。请参阅此问题。它指向您应该放在异常类上的注释(也可能检查这个这个@WebFault)


答案 2

Domenic D.有一个对我有用的正确答案,但我想扩展一下。

我的 Maven 项目使用 JDK 6 构建得很好,但是当我切换到使用 JDK 1.7 作为默认值时,构建就坏了。通过添加一个显式的 jaxb-impl 依赖项 w/ 版本,它可以工作,例如:

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.1</version>
    <dependencies>
        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.6</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
        ...
        </execution>
    </executions>
</plugin>

关于版本:此错误列在 https://java.net/jira/browse/JAXB-814。版本 2.2.4u2、2.2.5、2.3 已修复此问题


推荐