初始化jaxbconext时获取illegalannotationexceptions错误

7fyelxc5  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(192)

我试着注解两个类。我已经复习了很多遍,看到了一些类似的问题。但我认为我可能正确地注解了所有字段(并使用了(xmlacesstype.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;
    }
...

我认为我已经正确地注解了所有字段并使用了(xmlacestype.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>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题