민서네집

MyBatis 사용시 주의점 본문

Spring

MyBatis 사용시 주의점

브라이언7 2013. 4. 24. 17:58

1) "Mapped Statements collection does not contain value ...." 이라는 오류가 발생하는 경우.


다음 세가지가 일치해야 한다.


interface 파일명, Quert가 XML로 들어있는 mapper file, mapper namespace


[원문]


The three names have to match: 
 - interface = com.enlliance.inventory.mappers.SettingMapper.class 
 - mapper file = /com/enlliance/inventory/mappers/SettingMapper.xml 
 - mapper namespace = com.enlliance.inventory.mappers.SettingMapper 

If they don't match, it won't work. 


[출처] http://mybatis-user.963551.n3.nabble.com/Mapped-Statements-collection-does-not-contain-value-td2553948.html


2) org.mybatis.spring.mapper.MapperScannerConfigurer 를 등록하려고 하는데, basePackage 하위의 service의 interface도 ibatis의 DAO 빈으로 인식하는 오류가 발생하는 경우.


<!-- scan for mappers and let them be autowired -->

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

<property name="basePackage" value="com.sample.mgmt" />

<property name="annotationClass" value="org.springframework.stereotype.Repository"/>

</bean>


위에서처럼 annotationClass 속성을 추가해주고, DAO interface의 경우 @Repository 를 붙여주면 된다.


[출처] http://stackoverflow.com/questions/8999597/mybatis-spring-configuration-cant-autowire-mapper-beans


3) mybatis의 typeAliasClass를 하나의 디렉터리가 아니라 여러 개의 디렉터리로 분산시켜서 놓고 싶은 경우.


<!-- define the SqlSessionFactory -->

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

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

<property name="typeAliasesPackage" value="com.sample.mgmt" />

</bean>


위에서처럼 typeAliasesPackage 속성을 주면 이 하위 디렉터리의 클래스들은 모두 myBatis Mapper XML에서 parameter type 이나 result Type으로 사용할 수 있다.


'Spring' 카테고리의 다른 글

Transaction 설정 파일  (0) 2013.07.05
WebApplication 에서 Spring Bean 가져오기  (0) 2013.05.06
Java Custom Annotation Example  (0) 2013.04.23
Spring MVC From Handling Annotation Example  (0) 2013.04.23
Spring 과 myBatis 통합하기  (0) 2013.04.23
Comments