3

我有一个抽象类地址,以及两个从类地址继承的类。

A 类和 B 类。

所以我在谷歌中找到了@xmlSeeAlso我使用的注释,但我不知道它是否正确......

因为 stackTrace 打印了这个错误

com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 11 counts of IllegalAnnotationExceptions
Class has two properties of the same name "bairro"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getBairro()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.bairro
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "cep"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getCep()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.cep
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "codigoMunicipio"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getCodigoMunicipio()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.codigoMunicipio
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "codigoPais"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getCodigoPais()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.codigoPais
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "complemento"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getComplemento()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.complemento
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "logradouro"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getLogradouro()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.logradouro
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "municipio"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getMunicipio()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.municipio
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "numero"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getNumero()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.numero
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "pais"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getPais()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.pais
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "telefone"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getTelefone()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.telefone
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
Class has two properties of the same name "UF"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getUF()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.UF
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc

    at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at nfeProc.Teste.main(Teste.java:15)

那么怎么了?

4

1 回答 1

2

更新

将我的代码放入pastebin .. 为您解释一下,我的课程emitente 和destinatario 有一个来自enderecoEmitente 和enderecoDestinario 的带有endereco(地址)的字段,它们从Endereco http://pastebin.com/db0M3rG5扩展而来

在粘贴箱上使用您的代码我所要做的就是添加@XmlAccessorType(XmlAccessType.FIELD) to theEndereco 以使一切正常工作(因为该类具有注释字段)。

@XmlAccessorType(XmlAccessType.FIELD)
public class Endereco {

问题

您遇到的问题与继承无关,而是与您注释了字段而不是属性有关。默认情况下,JAXB 实现会将公共属性和带注释的字段视为已映射(请参阅: http ://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html ),这会导致您的使用冲突案子:

Class has two properties of the same name "pais"
    this problem is related to the following location:
        at public java.lang.String nfeProc.NFe.infNFe.Endereco.getPais()
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc
    this problem is related to the following location:
        at private java.lang.String nfeProc.NFe.infNFe.Endereco.pais
        at nfeProc.NFe.infNFe.Endereco
        at private nfeProc.NFe.infNFe.Endereco nfeProc.NFe.infNFe.emit.Emitente.endereco
        at nfeProc.NFe.infNFe.emit.Emitente
        at private nfeProc.NFe.infNFe.emit.Emitente nfeProc.NFe.infNFe.InfNFe.emitente
        at nfeProc.NFe.infNFe.InfNFe
        at private nfeProc.NFe.infNFe.InfNFe nfeProc.NFe.NFe.infNFe
        at nfeProc.NFe.NFe
        at private nfeProc.NFe.NFe nfeProc.NFeProc.nfe
        at nfeProc.NFeProc

解决方案

解决方案是对get方法(或set方法)进行注释,或者对字段进行注释并@XmlAccessorType(XmlAccessType.FIELD)在类或包级别进行指定。

JAXB 和继承

我已经写了很多关于 JAXB 和继承的文章,您可能会发现以下内容很有帮助:

于 2013-09-05T15:52:55.597 回答