zoukankan      html  css  js  c++  java
  • mybatis mapper加载原理

    流程
    1.MapperScannerConfigurer#postProcessBeanDefinitionRegistry修改beanDefition
    2.ClassPathMapperScanner扫描所有mapper
    3.org.mybatis.spring.mapper.ClassPathMapperScanner#doScan真正扫描
    4.org.mybatis.spring.mapper.ClassPathMapperScanner#processBeanDefinitions设置beanClass为MapperFactoryBean
    5.MapperFactoryBean产生mapper的代理类

    核心代码
    org.mybatis.spring.mapper.ClassPathMapperScanner#processBeanDefinitions
    private void processBeanDefinitions(Set<BeanDefinitionHolder> beanDefinitions) {
        GenericBeanDefinition definition;
        for (BeanDefinitionHolder holder : beanDefinitions) {
          definition = (GenericBeanDefinition) holder.getBeanDefinition();
    
          if (logger.isDebugEnabled()) {
            logger.debug("Creating MapperFactoryBean with name '" + holder.getBeanName() 
              + "' and '" + definition.getBeanClassName() + "' mapperInterface");
          }
    
          // the mapper interface is the original class of the bean
          // but, the actual class of the bean is MapperFactoryBean
          definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName()); // issue #59
        // 设置BeanClass为MapperFactory definition.setBeanClass(this.mapperFactoryBean.getClass()); definition.getPropertyValues().add("addToConfig", this.addToConfig); boolean explicitFactoryUsed = false; if (StringUtils.hasText(this.sqlSessionFactoryBeanName)) { definition.getPropertyValues().add("sqlSessionFactory", new RuntimeBeanReference(this.sqlSessionFactoryBeanName)); explicitFactoryUsed = true; } else if (this.sqlSessionFactory != null) { definition.getPropertyValues().add("sqlSessionFactory", this.sqlSessionFactory); explicitFactoryUsed = true; } if (StringUtils.hasText(this.sqlSessionTemplateBeanName)) { if (explicitFactoryUsed) { logger.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored."); } definition.getPropertyValues().add("sqlSessionTemplate", new RuntimeBeanReference(this.sqlSessionTemplateBeanName)); explicitFactoryUsed = true; } else if (this.sqlSessionTemplate != null) { if (explicitFactoryUsed) { logger.warn("Cannot use both: sqlSessionTemplate and sqlSessionFactory together. sqlSessionFactory is ignored."); } definition.getPropertyValues().add("sqlSessionTemplate", this.sqlSessionTemplate); explicitFactoryUsed = true; } if (!explicitFactoryUsed) { if (logger.isDebugEnabled()) { logger.debug("Enabling autowire by type for MapperFactoryBean with name '" + holder.getBeanName() + "'."); } definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); } } }

      

  • 相关阅读:
    TensorFlow从0到1之TensorFlow实现多元线性回归(11)
    TensorFlow从0到1之TensorFlow实现简单线性回归(10)
    TensorFlow从0到1之TensorFlow csv文件读取数据(9)
    TensorFlow从0到1之TensorFlow优化器(8)
    TensorFlow从0到1之TensorFlow损失函数(7)
    TensorFlow从0到1之回归算法(6)
    Python爬虫小白入门(六)爬取披头士乐队历年专辑封面-网易云音乐
    Python爬虫小白入门(五)PhatomJS+Selenium第二篇
    Python爬虫小白入门(四)PhatomJS+Selenium第一篇
    Python爬虫小白入门(三)BeautifulSoup库
  • 原文地址:https://www.cnblogs.com/seekwind/p/12560501.html
Copyright © 2011-2022 走看看