공부/Spring

[ERROR] org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception

leejinwoo1126 2022. 6. 12. 11:55
반응형

개요

  • spring batch clone project 테스트 하면서 공공 API xml 데이터 parsing 테스트 진행
  • dto 객체에 mapping 처리 해주는 과정에서 jaxb 에러 발생

에러

Caused by: org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 13 counts of IllegalAnnotationExceptions

(생략) 클래스에 동일한 이름 "year"을(를) 사용하는 속성이 두 개 있습니다.
this problem is related to the following location:
at public java.lang.Integer com.test.housebatch.core.dto.AptDealDto.getYear()
at com.fastcampus.housebatch.core.dto.AptDealDto
this problem is related to the following location:
at private java.lang.Integer com.test.housebatch.core.dto.AptDealDto.year
at com.fastcampus.housebatch.core.dto.AptDealDto

코드

package com.test.housebatch.core.dto;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

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

/**
 * 아파트 실거래가 각각의 정보를 담는 객체 ( from XML )
 */
@ToString
@Getter
@Setter          // *얘가 문제였음
@XmlRootElement(name = "item") // jaxb 라이브러리 통해 parsing 수월하게 해줌
public class AptDealDto {
    // XML API 각 요소 맵핑
    @XmlElement(name = "거래금액")
    private String dealAmount;

    @XmlElement(name = "건축년도")
    private Integer builtYear;

    @XmlElement(name = "년")
    private Integer year;

    @XmlElement(name = "법정동")
    private String dong;

    @XmlElement(name = "아파트")
    private String aptName;

    @XmlElement(name = "월")
    private Integer month;

    @XmlElement(name = "일")
    private Integer day;

    @XmlElement(name = "전용면적")
    private Double exclusiveArea;

    @XmlElement(name = "지번")
    private String jibun;

    @XmlElement(name = "지역코드")
    private String regionalCode;

    @XmlElement(name = "층")
    private Integer floor;

    @XmlElement(name = "해제사유발생일")
    private String dealCanceledDate;

    @XmlElement(name = "해제여부")
    private String dealCanceled;
}

해결

  • @Setter만 지워주면 됨
반응형