MyBatis整合Spring的实现(18)

Stella981
• 阅读 345

例子

同一个命名空间,但是有2个配置文件,A配置文件依赖于B配置文件信息,但是在加载时,先加载B配置文件的话,那么就会报错,前面章节已经捕获了此异常并把相应的配置添加到Configuration(全局配置类)中,这里就是在加载A配置文件后,再次加载B配置文件,也就把B配置信息添加到Configuration(全局配置类)里,下面就来看一下代码吧。

1 方法parsePendingResultMaps

private void parsePendingResultMaps() {
    Collection<ResultMapResolver> incompleteResultMaps = configuration.getIncompleteResultMaps();
    synchronized (incompleteResultMaps) {
      Iterator<ResultMapResolver> iter = incompleteResultMaps.iterator();
      while (iter.hasNext()) {
        try {
          iter.next().resolve();
          iter.remove();
        } catch (IncompleteElementException e) {
          // ResultMap is still missing a resource...
        }
      }
    }
}

2 方法parsePendingChacheRefs

private void parsePendingChacheRefs() {
  Collection<CacheRefResolver> incompleteCacheRefs = configuration.getIncompleteCacheRefs();
  synchronized (incompleteCacheRefs) {
      Iterator<CacheRefResolver> iter = incompleteCacheRefs.iterator();
      while (iter.hasNext()) {
          try {
              iter.next().resolveCacheRef();
              iter.remove();
          } catch (IncompleteElementException e) {
              // Cache ref is still missing a resource...
          }
      }
  }
}

3 方法parsePendingStatements

private void parsePendingStatements() {
  Collection<XMLStatementBuilder> incompleteStatements = configuration.getIncompleteStatements();
  synchronized (incompleteStatements) {
      Iterator<XMLStatementBuilder> iter = incompleteStatements.iterator();
      while (iter.hasNext()) {
          try {
              iter.next().parseStatementNode();
              iter.remove();
          } catch (IncompleteElementException e) {
              // Statement is still missing a resource...
          }
      }
  }
}

****以上3个方法就是因为加载顺序错误的重复处理逻辑,加载的代码与前面一样,这里不再分析。


总结

以上文章就是MyBatis对配置文件的初始化,这里至少分析了60%,对理解MyBatis已经够了。MyBatis也就剩最后一步了,建立SqlSessionFactory工厂,这个工厂也是唯一的,MyBatis默认使用的是org.apache.ibatis.session.defaults.DefaultSqlSessionFactory类。这里以后在分析。

点赞
收藏
评论区
推荐文章
Element 'configuration' cannot have character [children], because the type's content type is element-only.
整合springbootmybatis时copy网上的配置,然后报错了。<configuration       <!mybatis用于生成代码的配置文件  <configurationFilesrc/main/resources/gener
Stella981 Stella981
2年前
Dubbo 扩展点加载机制:从 Java SPI 到 Dubbo SPI
!(https://oscimg.oschina.net/oscnet/up1aa4ada0efc8a144d35d25b3443d951c7e3.JPEG)SPI全称为ServiceProviderInterface,是一种服务发现机制。当程序运行调用接口时,会根据配置文件或默认规则信息加载对应的实现类。所以在程序中并没有直接指定使用接口
Stella981 Stella981
2年前
Spring boot 配置文件,配置注解详解 (properties 和yml )
从其他框架来看我们都有自己的配置文件,hibernate有hbm,mybatis有properties,同样,Springboot也有全局配置文件。Springboot使用一个全局的配置文件,而且配置文件的名字是固定的。有两种application.propertiesapplication.yml spring
Easter79 Easter79
2年前
SpringMVC与SpringBoot配置文件的加载区别
一、SpringMVC:配置文件在classpath下。在web.xml中配置加载。以下项目为示例其中引用关系为1. applicationContextdao.xml引用了mybatis文件夹中的配置文件2. applicationContextshiro.xml引用了shiro文件夹中的配置文件3. sprin
Wesley13 Wesley13
2年前
Spring整合activiti配置processEngine
配置xml数据时,可以直接在配置文件中填写,也可以采用properties配置文件的方式加载。采用配置文件的方式需要使用到${参数}的方式获取。引用配置文件的方式:<context:propertyplaceholderlocation"classpath:properties文件目录"/applic
Easter79 Easter79
2年前
SSM_基于传统web项目
1.这是一个单模块的项目!有四个配置文件,mybaits,spring。springmvc,web.xml!2.web.xml配置文件,导入spring和springmvc的配置文件,spring配置文件中,获取sqlsession,以及关联mybatis的mpper(增删改查)文件3.mybatis的配置文件则可以不用写
Stella981 Stella981
2年前
FastDFS图片服务器实现图片上传
一、传统使用1.将fastdfs\_client.jar导入工程2.加载配置文件(如conf.properties),配置文件中的内容就是tracker服务的地址。配置文件内容:tracker\_server192.168.25.133:221223.把commonsio、fileupload的jar包添加到工程中4.页面代码!
Stella981 Stella981
2年前
Spring Cloud Alibaba Nacos Config 的使用
一、需求主要实现nacos作为配置中心的一些使用方法。二、实现功能1、加载productproviderdev.yaml配置文件2、实现配置的自动刷新3、实现加载多个配置文件
Easter79 Easter79
2年前
SpringIOC
XML方式:IOC:控制反转的底层原理就是:工厂模式反射配置文件DI:依赖注入就是通过配置文件设置属性值BeanFactory 是老版本的工厂类:调用getBean的时候,才会生成类的实例ApplicationContext 是新版本的工厂类:加载配置文件的时候,就会将Spring管理的类
Stella981 Stella981
2年前
SSM_基于传统web项目
1.这是一个单模块的项目!有四个配置文件,mybaits,spring。springmvc,web.xml!2.web.xml配置文件,导入spring和springmvc的配置文件,spring配置文件中,获取sqlsession,以及关联mybatis的mpper(增删改查)文件3.mybatis的配置文件则可以不用写