【问题标题】:JAXB - IllegalAnnotationExceptionsJAXB - IllegalAnnotationExceptions
【发布时间】:2014-02-20 21:59:24
【问题描述】:

我有一个这样的 XSD:

<xs:element name="Measure">
 <xs:complexType>
  <xs:sequence>
    <xs:element minOccurs="1" ref="Measure_Id"/>
    <xs:choice minOccurs="1" maxOccurs ="4">
        <xs:element ref="Measure_Value"/>
        <xs:element ref="Measure_Value_Max"/>
        <xs:element ref="Measure_Value_Min"/>
        <xs:element ref="Measure_Value_Average"/> 
    </xs:choice>
    <xs:element minOccurs="0" ref="Files"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

特别是,对于&lt;xs:choice&gt;,我想指定元素Measure 必须至少有一种Measure_Value。 不幸的是,这种代码会产生异常:

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:1 个 IllegalAnnotationExceptions 计数 对于元素 {}Measure_Value_Max.

,没有带有 @XmlElementDecl 的 ObjectFactory。

我必须做些什么来解决这个问题?

我使用Netbeans 7.4jdk1.7

此外,在我的架构的另一部分,这种类型的限制可以正常工作!为什么?

<xs:element name="UD_Info">
 <xs:complexType>
  <xs:sequence>
    <xs:element minOccurs="1" ref="UD_Identificator"/> 
    <xs:choice minOccurs="1" maxOccurs ="3">
        <xs:element ref="UD_Measures"/>
        <xs:element ref="UD_Alarms"/>
        <xs:element ref="UD_Diagnostics"/>
    </xs:choice>        
  </xs:sequence>
 </xs:complexType>
</xs:element>

堆栈跟踪:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/francesco/.m2/repository/org/slf4j/slf4j-log4j12/1.7.6/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/home/francesco/.m2/repository/ch/qos/logback/logback-classic/1.0.6/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions

There's no ObjectFactory with an @XmlElementDecl for the element {}Measure_Value_Max.
this problem is related to the following location:
    at protected java.util.List com.fra.jaxb.Measure.measureValueOrMeasureValueMaxOrMeasureValueMin
    at com.fra.jaxb.Measure
    at protected java.util.List com.fra.jaxb.UDMeasures.measure
    at com.fra.jaxb.UDMeasures
    at protected java.util.List com.fra.jaxb.UDInfo.udMeasuresOrUDAlarmsOrUDDiagnostics
    at com.fra.jaxb.UDInfo

at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:66)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:405)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:253)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:84)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:248)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:235)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:432)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:637)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584)
at com.fra.mavenparser.unMarsh.doInfr(unMarsh.java:56)
at com.fra.mavenparser.Parser.main(Parser.java:26)

【问题讨论】:

    标签: java xml jaxb xsd


    【解决方案1】:

    要获取ObjectFactory 进程,您需要将其作为用于引导JAXBContext 的类之一传入,或者在生成模型的包名称上创建JAXBContext

    【讨论】:

    • 如果我很好理解你的答案,我已经生成了类,并且在没有元素 Measure 必须具有至少一种类型的 Measure_Value 的规范的情况下,所有类都可以完美运行。当我插入那种类型的指定(你可以在代码中看到)时,我会回复这个异常。
    • @Zany - 你是如何创建你的JAXBContext 的?您还可以编辑您的问题以包含更多堆栈跟踪吗?
    • 我使用 xcj 将模式绑定到类(我将在问题中插入堆栈跟踪信息)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    相关资源
    最近更新 更多