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的掃描路徑