[error] spring mybatis 오류

공수정·2021년 10월 26일
0

error

목록 보기
5/10
  • 개발환경
    - 윈도우
    - 자바 1.8
    - tomcat 8.0

  • 문제상황

    mybatis test 코드에서는 문제가 없이 잘 실행이 되는데, 실제 쿼리를 작성한 파일과 연결이 안되는건지 dao에서 sqlsession을 이용해 selectList 메서드를 이용한 부분에서 자꾸 오류가 났다.

  • 에러메세지

    nested exceptio Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for VTSword.listn is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.apache.ibatis.session.SqlSessionFactory] is defined: expected single matching bean but found 2: sqlSeesionFactory,sqlSessionFactoryBean

  • 원인

    sql이 적힌 xml파일 경로 설정이 잘못되어있었다.
    xml파일이 resources 폴더 아래에 mapper폴더에 있는 상황이었고,
    /resources/** url은 /resources/로 mapping이 되어있어서 경로에서 resources를 제외한 그 이후부터 작성했어야했는데, /resources/~이런식으로 작성되어있어서 되지 않았다.
    여러 시도를 해본다고 /src/~이런식으로도 작성해봤는데 이것도 되지 않았다.
    검색을 해보면서 알게 된 사실인데, 이 error는 이 경로 설정 이외에도
    1. mapper id가 틀린 경우
    2. parameter와 bean의 field명이 다른 경우
    3. sql.xml에서 정의된 namespace와 DAO에서 호출하는 namespace가 다를 경우
    4. mapper가 정의되어 있지 않거나 오타가 난경우
    5. mapper에 정의된 namespace에 명칭이 같은 application 내에 중복 될 경우
    의 경우에도 생길 수 있는 오류였다.

  • 해결방법

    applicationContext.xml 파일의 sqlSessionFactoryBean에서
    /resources/~이렇게 시작한 경로에서 resources이하 경로만 적어주니 잘 실행이 되었다.

profile
계속해서 공부하는 개발자입니다 :)

0개의 댓글