com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:2个IllegalAnnotationExceptions计数有两个名为 - java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "channelType",
    "channelSubType",
    "suffix",
    "userDetail",
    "cardDetail"
})
@XmlRootElement(name = "CardCreationRequest")
public class CardCreationRequest extends BaseRequest
    implements Serializable
{

    @XmlElement(required = true, type = Integer.class, nillable = true)
    protected Integer channelType;
    @XmlElement(required = true, type = Integer.class, nillable = true)
    protected Integer channelSubType;

    @XmlElement(required = true, nillable = true)
    protected String suffix;

    @XmlElement(name="UserDetail", required = true)
    protected UserDetail userDetail;
    @XmlElement(name="CardDetail",required = true)
    protected CardDetail cardDetail;


}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserDetail", propOrder = {
    "title",
    "lastName",
    "firstName",
    "nickName",
    "dob",
    "addr1",
    "addr2",
    "city",
    "state",
    "county",
    "zip",
    "country",
    "tel",
    "mobtel",
    "telExt",
    "ssn",
    "fein",
    "selfEmployed",
    "middleInitial",
    "mothersmaid",
    "salutation",
    "relation",
    "holderID",
    "others",
    "busNum",
    "busNumExt",
    "faxNum",
    "faxExt",
    "driverlicNum",
    "driverlicState",
    "dependents",
    "fedtaxID",
    "companyName",
    "emerAddr1",
    "emerAddr2",
    "emerCity",
    "emersState",
    "emerZip",
    "emerCounty",
    "emerCountry",
    "emerPhone",
    "emerExt",
    "vip",
    "recipID",
    "pagerNum",
    "maritalStatus",
    "gender",
    "email",
    "language",
    "accessCode",
    "nameOnCard",
    "loginID",
    "itemSrc",
    "birthCity",
    "birthState",
    "hsGradYr",
    "collegeGradYr",
    "maidenName"
    })

public class UserDetail
    implements Serializable
{

    public UserDetail() {
        super();
        // TODO Auto-generated constructor stub
    }

    @XmlElement(required = true, nillable = true)
    protected String title;
    @XmlElement(required = true, nillable = true)
    protected String lastName;
    @XmlElement(required = true, nillable = true)
    protected String firstName;
    @XmlElement(required = true, nillable = true)
    protected String nickName;
    @XmlElement(name = "DOB", required = true, type = String.class, nillable = true)
    @XmlJavaTypeAdapter(Adapter2 .class)
    @XmlSchemaType(name = "date")
    protected Date dob;
    @XmlElement(required = true, nillable = true)
    protected String addr1;
    @XmlElement(required = true, nillable = true)
    protected String addr2;
    @XmlElement(required = true, nillable = true)
    protected String city;
    @XmlElement(required = true, nillable = true)
    protected String state;
    @XmlElement(required = true, nillable = true)
    protected String county;
    @XmlElement(required = true, nillable = true)
    protected String zip;
    @XmlElement(required = true, nillable = true)
    protected String country;
    @XmlElement(required = true, nillable = true)
    protected String tel;
    @XmlElement(required = true, nillable = true)
    protected String mobtel;
    @XmlElement(required = true, nillable = true)
    protected String telExt;
    @XmlElement(name = "SSN", required = true, nillable = true)
    protected String ssn;
    @XmlElement(name = "FEIN", required = true, nillable = true)
    protected String fein;
    @XmlElement(required = true, nillable = true)
    protected String selfEmployed;
    @XmlElement(required = true, nillable = true)
    protected String middleInitial;
    @XmlElement(required = true, nillable = true)
    protected String mothersmaid;
    @XmlElement(required = true, nillable = true)
    protected String salutation;
    @XmlElement(required = true, nillable = true)
    protected String relation;
    @XmlElement(required = true, nillable = true)
    protected String holderID;
    @XmlElement(required = true, nillable = true)
    protected String others;
    @XmlElement(required = true, nillable = true)
    protected String busNum;
    @XmlElement(required = true, nillable = true)
    protected String busNumExt;
    @XmlElement(required = true, nillable = true)
    protected String faxNum;
    @XmlElement(required = true, nillable = true)
    protected String faxExt;
    @XmlElement(required = true, nillable = true)
    protected String driverlicNum;
    @XmlElement(required = true, nillable = true)
    protected String driverlicState;
    @XmlElement(required = true, nillable = true)
    protected String dependents;
    @XmlElement(required = true, nillable = true)
    protected String fedtaxID;
    @XmlElement(required = true, nillable = true)
    protected String companyName;
    @XmlElement(required = true, nillable = true)
    protected String emerAddr1;
    @XmlElement(required = true, nillable = true)
    protected String emerAddr2;
    @XmlElement(required = true, nillable = true)
    protected String emerCity;
    @XmlElement(required = true, nillable = true)
    protected String emersState;
    @XmlElement(required = true, nillable = true)
    protected String emerZip;
    @XmlElement(required = true, nillable = true)
    protected String emerCounty;
    @XmlElement(required = true, nillable = true)
    protected String emerCountry;
    @XmlElement(required = true, nillable = true)
    protected String emerPhone;
    @XmlElement(required = true, nillable = true)
    protected String emerExt;
    @XmlElement(name = "VIP", required = true, nillable = true)
    protected String vip;
    @XmlElement(required = true, nillable = true)
    protected String recipID;
    @XmlElement(required = true, nillable = true)
    protected String pagerNum;
    @XmlElement(required = true, nillable = true)
    protected String maritalStatus;
    @XmlElement(required = true, nillable = true)
    protected String gender;
    @XmlElement(required = true, nillable = true)
    protected String email;
    @XmlElement(required = true, nillable = true)
    protected String language;
    @XmlElement(required = true, nillable = true)
    protected String accessCode;
    @XmlElement(required = true, nillable = true)
    protected String nameOnCard;
    @XmlElement(required = true, nillable = true)
    protected String loginID;
    @XmlElement(required = true, nillable = true)
    protected String itemSrc;
    @XmlElement(required = true, nillable = true)
    protected String birthCity;
    @XmlElement(required = true, nillable = true)
    protected String birthState;
    @XmlElement(name = "HSGradYr", required = true, type = Integer.class, nillable = true)
    protected Integer hsGradYr;
    @XmlElement(name = "CollegeGradYr", required = true, type = Integer.class, nillable = true)
    protected Integer collegeGradYr;
    @XmlElement(required = true, nillable = true)
    protected String maidenName;
    @XmlElement(required = true, nillable = true)




}
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CardsWS': Invocation of init method failed; nested exception is javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:962)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1603)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:357)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:246)
    at org.apache.cxf.jaxws.EndpointImpl.publish(EndpointImpl.java:525)
    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 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1581)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1522)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
    ... 26 more
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:324)
    at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:474)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:690)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:536)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:248)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:205)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
    at org.apache.cxf.frontend.ServerFactoryBean.create(ServerFactoryBean.java:159)
    at org.apache.cxf.jaxws.JaxWsServerFactoryBean.create(JaxWsServerFactoryBean.java:211)
    at org.apache.cxf.jaxws.EndpointImpl.getServer(EndpointImpl.java:442)
    at org.apache.cxf.jaxws.EndpointImpl.doPublish(EndpointImpl.java:329)
    ... 35 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
There are two properties named "title" 
    this problem is related to the following location:
        at public java.lang.String wavecrest.orchestration.cardmanger.dto.UserDetail.getTitle()
        at wavecrest.orchestration.cardmanger.dto.UserDetail
        at protected wavecrest.orchestration.cardmanger.dto.UserDetail wavecrest.orchestration.cardmanger.dto.CardCreationRequest.userDetail
        at wavecrest.orchestration.cardmanger.dto.CardCreationRequest
        at private wavecrest.orchestration.cardmanger.dto.CardCreationRequest wavecrest.orchestration.endpoint.jaxws_asm.CreateCard.arg0
        at wavecrest.orchestration.endpoint.jaxws_asm.CreateCard
    this problem is related to the following location:
        at protected java.lang.String wavecrest.orchestration.cardmanger.dto.UserDetail.title
        at wavecrest.orchestration.cardmanger.dto.UserDetail
        at protected wavecrest.orchestration.cardmanger.dto.UserDetail wavecrest.orchestration.cardmanger.dto.CardCreationRequest.userDetail
        at wavecrest.orchestration.cardmanger.dto.CardCreationRequest
        at private wavecrest.orchestration.cardmanger.dto.CardCreationRequest wavecrest.orchestration.endpoint.jaxws_asm.CreateCard.arg0
        at wavecrest.orchestration.endpoint.jaxws_asm.CreateCard
Class has two properties of the same name "title"
    this problem is related to the following location:
        at public java.lang.String wavecrest.orchestration.cardmanger.dto.UserDetail.getTitle()
        at wavecrest.orchestration.cardmanger.dto.UserDetail
        at protected wavecrest.orchestration.cardmanger.dto.UserDetail wavecrest.orchestration.cardmanger.dto.CardCreationRequest.userDetail
        at wavecrest.orchestration.cardmanger.dto.CardCreationRequest
        at private wavecrest.orchestration.cardmanger.dto.CardCreationRequest wavecrest.orchestration.endpoint.jaxws_asm.CreateCard.arg0
        at wavecrest.orchestration.endpoint.jaxws_asm.CreateCard
    this problem is related to the following location:
        at protected java.lang.String wavecrest.orchestration.cardmanger.dto.UserDetail.title
        at wavecrest.orchestration.cardmanger.dto.UserDetail
        at protected wavecrest.orchestration.cardmanger.dto.UserDetail wavecrest.orchestration.cardmanger.dto.CardCreationRequest.userDetail
        at wavecrest.orchestration.cardmanger.dto.CardCreationRequest
        at private wavecrest.orchestration.cardmanger.dto.CardCreationRequest wavecrest.orchestration.endpoint.jaxws_asm.CreateCard.arg0
        at wavecrest.orchestration.endpoint.jaxws_asm.CreateCard

    at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:154)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:121)
    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 javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
    at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:268)
    at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:267)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:266)
    at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:172)
    at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:454)
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:322)
    ... 46 more

参考方案

当您同时注释字段和属性时,通常会出现此错误。由于指定了XmlAccessType.FIELD,因此只应注释该字段(实例变量)。

你有

@XmlAccessorType(XmlAccessType.FIELD)
public class UserDetail {

    @XmlElement
    private String title;

    @XmlElement
    public String getTitle() {
        return title;
    }

}

改成:

@XmlAccessorType(XmlAccessType.FIELD)
public class UserDetail {

    @XmlElement
    private String title;

    public String getTitle() {
        return title;
    }

}

这与异常告诉您的内容相符。它指向UserDetail.getTitle()UserDetail.title

Class has two properties of the same name "title"
    this problem is related to the following location:
        at public java.lang.String wavecrest.orchestration.cardmanger.dto.UserDetail.getTitle()
        at wavecrest.orchestration.cardmanger.dto.UserDetail
        at protected wavecrest.orchestration.cardmanger.dto.UserDetail wavecrest.orchestration.cardmanger.dto.CardCreationRequest.userDetail
        at wavecrest.orchestration.cardmanger.dto.CardCreationRequest
        at private wavecrest.orchestration.cardmanger.dto.CardCreationRequest wavecrest.orchestration.endpoint.jaxws_asm.CreateCard.arg0
        at wavecrest.orchestration.endpoint.jaxws_asm.CreateCard
    this problem is related to the following location:
        at protected java.lang.String wavecrest.orchestration.cardmanger.dto.UserDetail.title
        at wavecrest.orchestration.cardmanger.dto.UserDetail
        at protected wavecrest.orchestration.cardmanger.dto.UserDetail wavecrest.orchestration.cardmanger.dto.CardCreationRequest.userDetail
        at wavecrest.orchestration.cardmanger.dto.CardCreationRequest
        at private wavecrest.orchestration.cardmanger.dto.CardCreationRequest wavecrest.orchestration.endpoint.jaxws_asm.CreateCard.arg0
        at wavecrest.orchestration.endpoint.jaxws_asm.CreateCard

Java-搜索字符串数组中的字符串 - java

在Java中,我们是否有任何方法可以发现特定字符串是字符串数组的一部分。我可以避免出现一个循环。例如String [] array = {"AA","BB","CC" }; string x = "BB" 我想要一个if (some condition to tell wheth…

Java Scanner读取文件的奇怪行为 - java

因此,在使用Scanner类从文件读取内容时,我遇到了一个有趣的问题。基本上,我试图从目录中读取解析应用程序生成的多个输出文件,以计算一些准确性指标。基本上,我的代码只是遍历目录中的每个文件,并使用扫描仪将其打开以处理内容。无论出于何种原因,扫描程序都不会读取其中的一些文件(所有UTF-8编码)。即使文件不是空的,scanner.hasNextLine()在…

NoClassDefFoundError的可能原因 - java

我得到以下NoClassDefFoundError,这很奇怪,因为该类已经存在于库jar中。Exception in thread "main" java.lang.NoClassDefFoundError: abc/test/Test.java at java.lang.ClassLoader.defineClass1(Native M…

Java Globbing模式以匹配目录和文件 - java

我正在使用递归函数遍历根目录下的文件。我只想提取*.txt文件,但不想排除目录。现在,我的代码如下所示:val stream = Files.newDirectoryStream(head, "*.txt") 但是这样做将不会匹配任何目录,并且返回的iterator()是False。我使用的是Mac,所以我不想包含的噪音文件是.DS_ST…

直接读取Zip文件中的文件-Java - java

我的情况是我有一个包含一些文件(txt,png,...)的zip文件,我想直接按它们的名称读取它,我已经测试了以下代码,但没有结果(NullPointerExcepion):InputStream in = Main.class.getResourceAsStream("/resouces/zipfile/test.txt"); Buff…