2011-12-10 2 views
0

Spring RESTful 웹 서비스에서 JAXB를 사용하려고합니다. 내 코드는 다음과 같다 :JAXB SpringREST에서 도메인 객체의 ArrayList를 반환하는 동안 오류가 발생했습니다.

@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; 
} 
} 

Country.java 보이는 같은 : 나는 방법에 액세스 이제

@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 

이 오류가 발생하는 이유는 누구나 알 수 있습니까? 나는 annotaion 부분에서 잘못된 일을하고 있습니까 ??

도와주세요.

는 감사 Saroj 당신은 게터/세터와 필드 모두에 주석을 달 수 없습니다

+0

스프링 구성을 볼 수 있습니까? –

+0

나는이 기사가 과거에 매우 유용하다는 것을 발견했다 : http://java-diaries.blogspot.com/2011/02/restful-webservices-with-spring.html –

+0

안녕하세요, 알렉스, 고맙습니다. 링크 http://java-diaries.blogspot.com/2011/02/restful-webservices-with-spring.html에 나와있는 예제에 따라 주석을 변경했으며 완벽하게 정상적으로 작동했습니다. 다음과 같이 – user1061771

답변

0

, 당신은 그들 중 하나를 결정해야합니다.

관련 문제