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