在SpringREST中使用返回域对象的ArrayList时发生JAXB错误

在SpringREST中使用返回域对象的ArrayList时发生JAXB错误,spring,annotations,jaxb,Spring,Annotations,Jaxb,我试图在SpringRESTfulWebService中使用JAXB。 我的代码如下: @RequestMapping(value = "/countries", method = RequestMethod.GET, headers="Accept=application/xml, application/json") public @ResponseBody CountryList getCountry() { logger.debug("Provid

我试图在SpringRESTfulWebService中使用JAXB。 我的代码如下:

 @RequestMapping(value = "/countries",
        method = RequestMethod.GET,
        headers="Accept=application/xml, application/json")
 public @ResponseBody CountryList getCountry() {
  logger.debug("Provider has received request to get all persons");

  // Call service here
  CountryList result = new CountryList();
  result.setData(countryService.getAll());

  return result;
 }
CountryList.java类如下所示:

@XmlRootElement(name="countries")
public class CountryList {

 @XmlElement(required = true)
 public List<Country> data;

 @XmlElement(required = false)
 public List<Country> getData() {
  return data;
 }

 public void setData(List<Country> data) {
  this.data = data;
 }
}
@XmlRootElement(name="country")
public class Country {

    private Calendar createdDt;
    private String updatedBy;
    private String createdBy;
    private Long id;
    private String countryName;
    private Calendar updatedDt;

// getters and setters for all attributes goes here 

}
现在,当我访问getCountry()方法时,我得到以下异常

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "data"
    this problem is related to the following location:
        at public java.util.List com.cisco.bic.services.model.CountryList.getData()
        at com.cisco.bic.services.model.CountryList
    this problem is related to the following location:
        at public java.util.List com.cisco.bic.services.model.CountryList.data
        at com.cisco.bic.services.model.CountryList
有谁知道为什么会出现这个错误吗。我在注释部分做错了什么吗

请帮忙

问候
Saroj

你不能同时注释getter/setter和字段,你需要决定其中一个。我们可以看看你的spring配置吗?我发现这篇文章在过去非常有用:嗨,Alex,谢谢你的回复。我已经按照链接中给出的示例更改了注释,效果非常好。将my CountryList.java更改如下,效果很好:@XmlRootElement(name=“countries”)公共类CountryList实现了可序列化{/**/private static final long serialVersionUID=1431094580954491617L;私有列表国家/地区;公共国家/地区列表(){}公共国家/地区列表(列表国家/地区){this.countries=countries;}@xmlement(name=“country”)公共列表getCountries(){返回国家/地区;}public void setCountries(List countries){this.countries=countries;}}太棒了。我发现这篇文章是用Spring MVC快速启动和运行web服务的最佳文章。