首先来谈谈这个依赖包
mybatis开发团队为Spring Boot 提供了 MyBatis-Spring-Boot-Starter 。
首先,MyBatis-Spring-Boot-Starter will:
- Autodetect an existing DataSource.
- Will create and register an instance of a SqlSessionFactoryBean passing that DataSource as an input.
- Will create and register an instance of a SqlSessionTemplate got out of the SqlSessionFactoryBean.
- Autoscan your mappers, link them to the SqlSessionTemplate and register them to Spring context so they can be injected into your beans.
来源: http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/index.html
就是说,使用了该Starter之后,只需要定义一个DataSource即可,它会自动创建使用该DataSou