1. Download the Mybatis-spring.jar package.
2. Configure the spring and mybatis environments.
3. In the project I use Sqlsessionfactorybean to instantiate each interface. The specific configuration file code is as follows:
<BeanID= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean"> < Propertyname= "DataSource"ref= "Jdbcdatasource"/> < Propertyname= "Configlocation"value= "Classpath:/mybatis-config.xml"></ Property><!--<property name= "mapperlocations" value= "Com/oliver/spider/beans/*.xml" ></property> - </Bean> <BeanID= "Usermapper"class= "Org.mybatis.spring.mapper.MapperFactoryBean"> < Propertyname= "Mapperinterface"value= "Com.oliver.mapper.inter.ITestClassMapper" /> < Propertyname= "Sqlsessionfactory"ref= "Sqlsessionfactory"/> </Bean>
Then just use the usermapper as you would with a normal bean.
I do not use *mapper.xml files here, as for how to use, I am still in the exploration.
Implementing Spring and MyBatis consolidation in Java projects