<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name= "Annotationclass" value= "Org.springframework.stereotype.Repository"/>
<property name= "Basepackage" value= "Cn.jesong.webcall.report.dao"/>
<property name= "Sqlsessionfactory" ref= "Sqlsessionfactory"/>
</bean>
The advent of Mapperfactorybean is implemented using dynamic proxies instead of manually writing code that uses Sqlsessiondaosupport or sqlsessiontemplate to write data Access Objects (DAO).
<bean id= "Usermapper" class= "Org.mybatis.spring.mapper.MapperFactoryBean" ><property name= " Mapperinterface "value=" Org.mybatis.spring.sample.mapper.UserMapper "/><property name=" Sqlsessionfactory " ref= "Sqlsessionfactory"/></bean>
Org.mybatis.spring.sample.mapper.UserMapper is an interface, we create an Mapperfactorybean instance, and then inject this interface and Sqlsessionfactory (MyBatis provides the Sqlsessi Onfactory interface, Mapperfactorybean uses Sqlsessionfactory to create the sqlsession) two properties.
Later, if you want to use this Usermapper interface, inject the bean directly through spring, and then you can use it directly, and spring will create a dynamic proxy for this interface.
When it comes to using multiple mapperfactorybean, a definition must be very cumbersome, so mybatis-spring provides the Mapperscannerconfigurer class, It will look for the mapper under the Classpath and automatically create the Mapperfactorybean.
<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" ><property name= "Basepackage" value= " Org.mybatis.spring.sample.mapper "/></bean>
This configuration scans all the interfaces under Org.mybatis.spring.sample.mapper and then creates dynamic proxy classes for their respective interfaces.
Org.mybatis.spring.mapper.MapperScannerConfigurer class Effect