Org.mybatis.spring.mapper.MapperScannerConfigurer class Effect

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.