1. 本地加载
buildSqlSessionFactory构建SqlSessionFactory。
2.spring集成
1.web.xml中配置spring-mvc的配置文件
2.在spring-mvc中配置mybatis的配置
2.1 sqlSessionFactory
加载时间:实现InitializingBean的afterPropertiesSet方法。在afterPropertiesSet中调用buildSqlSessionFactory构建SqlSessionFactory。
配置内容:
- 配置dataSource
- entity的扫描路径
- xml的扫描路径
2.2 MapperScannerConfigurer bean类
加载时间:实现BeanDefinitionRegistryPostProcessor的postProcessBeanDefinitionRegistry方法。在postProcessBeanDefinitionRegistry方法中加载xml配置方法)
配置内容:
- 配置dao的扫描路径