250x250
반응형
Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Archives
Today
Total
관리 메뉴

BEAT A SHOTGUN

[TROUBLESHOOTING] argument type mismatch 본문

TROUBLESHOOTING

[TROUBLESHOOTING] argument type mismatch

thovy 2023. 11. 5. 14:55
728x90
반응형
SMALL

MyBatis를 사용하며
DTO 를 한 대 모아 요청 형태와 반환 형태를 정의해주고 싶었다.

public class testDTO {

    @Getter
    @Setter
    public class testReqDTO{
        private Integer id;
        private String title;
        private String content;
        private Time time;
    }

    @Getter
    @Setter
    public class testRespDTO{
        private String title;
        private String content = null;
    }
}

ERROR ❌

[ERROR] 2023-11-05 14:27:48.574 : o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Error instantiating class testDTO$testRespDTO with invalid types (testDTO) or values (1). Cause: java.lang.IllegalArgumentException: argument type mismatch] with root cause
java.lang.IllegalArgumentException: argument type mismatch

이런 형태를 중첩클래스라고 한다.

SOLUTION ✅

중첩 클래스는 static 으로 선언되어야 한다.

중첩된 클래스가 non-static으로 선언되면 해당 클래스의 인스턴스에는 외부 클래스의 참조가 포함되므로, 직렬화에서 문제가 발생할 수 있다.

특히나 batis를 사용한다면 batis 가 매핑하는 과정에서 문제가 발생할 수 있습니다.

public class testDTO {

    @Getter
    @Setter
❌  public class testReqDTO{
✅  public static class testReqDTO{
        ...
    }

    @Getter
    @Setter
❌  public class testRespDTO{
✅  public static class testRespDTO{
        ...
    }
}
728x90
반응형
LIST
Comments