初始化 JAXBConetxt 时出现 IllegalAnnotationExceptions 错误

时间:2021-01-06 12:05:45

标签: java compiler-errors jaxb maven-jaxb2-plugin jaxb2-maven-plugin

我正在尝试注释两个类。我已经多次查看它们并看到一些类似的问题。但我认为我可能会正确注释所有字段(并使用 (XmlAccessType.FIELD) 这是我所看到的错误可能是原因......)但我仍然收到以下错误:

import java.util.Date;
import java.util.List;
@XmlType(name = "referenceData", namespace = "http:/tech.uc3.cnebrera.com/lesson9")
@XmlAccessorType(XmlAccessType.FIELD) 

/**
* This class represents the reference of the market
*/
public class ReferenceData
{
   /** a List with the Instruments information **/
   @XmlElement(name="instrument")
   @JsonProperty(value="instrument")
  private List<Instrument> listOfInstruments;
 
  
  
   /** a int that identifies the market */
   @XmlAttribute(name="marketId")
   @JsonProperty(value="marketId")
   private int marketId;
  
  
  /** a {@link java.lang.String} with the algorithm identifier */
    @XmlAttribute(name="algorithmIdentifier")
    @JsonProperty(value="algorithmIdentifier")
   private String algorithmIdentifier;

  

  public int getMarketId()
  {
      return marketId;
  }

  public void setMarketId(int marketId)
  {
      this.marketId = marketId;
  }

  public String getAlgorithmIdentifier()
  {
      return algorithmIdentifier;
  }

  public void setAlgorithmIdentifier(String algorithmIdentifier)
  {
      this.algorithmIdentifier = algorithmIdentifier;
  }

  public List<Instrument> getListOfInstruments()
  {
      return listOfInstruments;
  }

  public void setListOfInstruments(List<Instrument> listOfInstruments)
  {
      this.listOfInstruments = listOfInstruments;
  }
...

然后:

@XmlRootElement(name = "instrument", namespace = "http:/tech.uc3.cnebrera.com/lesson9")
@XmlAccessorType(XmlAccessType.FIELD)

/**
 * This class represents the instrument info
 */
public class Instrument
{
    /** a int that identifies the instrument */
    @XmlAttribute(name="instrumentId")
    @JsonProperty(value="instrumentId")
    private int instrumentId;
    
    

    /** human understood representation of the security */
    @XmlAttribute(name="symbol")
    @JsonProperty(value="symbol")
    private String symbol;
   

    public int getInstrumentId()
    {
        return instrumentId;
    }

    public void setInstrumentId(int instrumentId)
    {
        this.instrumentId = instrumentId;
    }

    public String getSymbol()
    {
        return symbol;
    }

    public void setSymbol(String symbol)
    {
        this.symbol = symbol;
    }
...

我认为我已正确注释所有字段并使用 (XmlAccessType.FIELD) 这是我所看到的错误可能是原因...但我仍然收到以下错误:

Error initialising the JAXBConetxt
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
    at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:106)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:466)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:298)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:141)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1163)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:145)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:247)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:234)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:441)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:641)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:584)```

拜托,有人能给点建议吗?

我的 XML 看起来像:

<xs:element name="referenceData">
        <xs:complexType>
            <xs:annotation>
                <xs:documentation xml:lang="en">
                   This element is the root element of the document and represents all the reference data
                    of the market
                </xs:documentation>
            </xs:annotation>
            <xs:sequence>
                <xs:element name="instrument" type="l9:Instrument" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="marketId" type="xs:int"/>
            <xs:attribute name="algorithmIdentifier" type="xs:string"/>
        </xs:complexType>

    </xs:element>


    <xs:complexType name="Instrument">
        <xs:annotation>
            <xs:documentation xml:lang="en">
                This complexType represents the info of and Instrument
            </xs:documentation>
        </xs:annotation>
        <xs:attribute name="instrumentId" type="xs:int"/>
        <xs:attribute name="symbol" type="xs:string"/>
    </xs:complexType>
</xs:schema>

0 个答案:

没有答案