2个非法注释例外计数

Liv*_*ing 9 java xml jaxb

我有一个Customer和CustomerFullAddress类,我正在使用JAXB来尝试生成XML文件

<Customer CustomerID="GREAL">
    <CompanyName>Great Lakes Food Market</CompanyName>
    <ContactName>Howard Snyder</ContactName>
    <ContactTitle>Marketing Manager</ContactTitle>
    <Phone>(503) 555-7555</Phone>
    <FullAddress>
        <Address>2732 Baker Blvd.</Address>
        <City>Eugene</City>
        <Region>OR</Region>
        <PostalCode>97403</PostalCode>
        <Country>USA</Country>
    </FullAddress>
</Customer>
Run Code Online (Sandbox Code Playgroud)

Customer Class如下所示(它不是完整的实现)

package org.abc.customers;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "customer")
@XmlType (propOrder = { "companyName", "contactName", "contactTitle", "phone" })

public class Customer {

*@XmlElement(name = "customerfulladdress")
private CustomerFullAddress custAdd;*

private String companyName;
private String contactName;
private String contactTitle;
private int phone;

public CustomerFullAddress getCustAddress() {
return custAdd;
}

public void setCustAddress(CustomerFullAddress custAdd) {
this.custAdd = custAdd;
}
...
Run Code Online (Sandbox Code Playgroud)

而CustomerFullAddress是

package org.abc.customers;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "customerfulladdress")
//If you want you can define the order in which the fields are written
//Optional
@XmlType(propOrder = { "address", "city", "region", "postalCode", "country" })

public class CustomerFullAddress {

private String address;
...

public String getAddress() {
    return address;
}
public void setAddress(String address) {
    this.address = address;
}
.....
 }
Run Code Online (Sandbox Code Playgroud)

而错误是

线程"main"中的异常com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions的2个计数属性custAdd存在但未在@ XmlType.propOrder中指定此问题与以下位置有关:at private org .abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd at org.abc.customers.Customer属性custAddress存在但未在@ XmlType.propOrder中指定此问题与以下位置有关:at public org.abc.来自org.abc.customers.Customer的customers.CustomerFullAddress org.abc.customers.Customer.getCustAddress()

谢谢你看看!

dar*_*man 11

从JavaDoc for @XmlType:

propOrder

必须列出映射到XML Schema元素的所有JavaBean属性.

您需要将CustomerFullAddress属性添加到propOrderfor Customer.