Mybatis加載過程分析

1. 本地加載

buildSqlSessionFactory構建SqlSessionFactory。

2.spring集成

1.web.xml中配置spring-mvc的配置文件

2.在spring-mvc中配置mybatis的配置

2.1 sqlSessionFactory

加載時間:實現InitializingBean的afterPropertiesSet方法。在afterPropertiesSet中調用buildSqlSessionFactory構建SqlSessionFactory。

配置內容:

  1. 配置dataSource
  2. entity的掃描路徑
  3. xml的掃描路徑
2.2 MapperScannerConfigurer bean類

加載時間:實現BeanDefinitionRegistryPostProcessor的postProcessBeanDefinitionRegistry方法。在postProcessBeanDefinitionRegistry方法中加載xml配置方法)

配置內容:

  1. 配置dao的掃描路徑
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章