MyBatis integration of Spring's mapperlocations configuration issues

Source: Internet
Author: User

Today's attempt to integrate MyBatis with spring is the question of whether to configure mapperlocations when configuring Sqlsessionfactory.

<BeanID= "Sessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean">    < Propertyname= "DataSource"ref= "DataSource"></ Property>    < Propertyname= "Typealiasespackage"value= "Com.fan.entity"/>      <!--when the MyBatis XML file and the Mapper interface are not under the same package, the path to the XML file needs to be specified with the Mapperlocations property. * is a wildcard character, representing all files, * * representing all directories -       < Propertyname= "Mapperlocations"value= "Classpath:com/fan/mapper/*.xml" />        <!--you can also introduce the MyBatis configuration file <property name= "configlocation" value= "Classpath:mybatis/sqlmapconfig.xml" ></proper Ty> -</Bean><!--Scan The directory in the Com.lanyuan.mapper directory by scanning mode mapper -<Beanclass= "Org.mybatis.spring.mapper.MapperScannerConfigurer">    < Propertyname= "Basepackage"value= "Com.fan.mapper"></ Property></Bean>

Conclusion: If Mapper.xml and Mapper.class are under the same package and have the same name, spring scans the Mapper.class and automatically scans mapper.xml with the same name and assembles to Mapper.class.

If Mapper.xml and Mapper.class are not under the same package or a different name, you must use the configuration mapperlocations to specify the location of the mapper.xml.

Spring is determined by identifying the value of <mapper namespace= "Com.fan.mapper.UserDao" > Namespace in Mapper.xml to determine the corresponding mapper.class.

MyBatis integration of Spring's mapperlocations configuration issues

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.