본문 바로가기

개발 이야기/Java

mapped statements collection does not contain value for mybatis

Spring 3.X, 4.X의 MyBatis 연동시 mapperLocation에 모든 XML을 기술하기 위하여 아래와 같은 코드를 기본적으로 사용하게 됩니다.


<!-- MyBatis -->

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

<property name="dataSource" ref="dataSource" />

<property name="configLocation" value="conf/mybatis-config.xml" />

<property name="mapperLocations" value="classpath:com/osci/**/sql/*.xml" />

</bean>

<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">

<constructor-arg ref="sqlSessionFactory" />

</bean>


위의 mapperLocations의 classpath:com/osci 형태로 파일을 구성했을 경우 jar 파일에서 해당 Mapper XML파일을 찾지 못해 "mapped statements collection does not contain value for " 에러를 발생하게 됩니다.


인터넷에서 다른 여러가지 상황에 대한 부분을 많이 언급하고 있지만 핵심적인 부분으로 아래와 같이 classpath 정보를 수정해보도록 합니다.

<property name="mapperLocations" value="classpath*:com/osci/**/sql/*.xml" />


차이점: classpath vs classpath*


참고 URL: https://mybatis.github.io/spring/factorybean.html