mybatis-启动解析流程

在 MyBatis 中负责加载配置文件的核心类有三个
XMLConfigBuilder: 主要负责解析 mybatis-config.xml;
XMLMapperBuilder: 主要负责解析映射配置 Mapper.xml 文件;
XMLStatementBuilder: 主要负责解析映射配置文件中的 SQL 节点;


 

解析重要对象Configuration

核心属性如下:

public class Configuration {

  /*TypeAlias注册中心*/
  protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();
  //-------------------------------------------------------------
  /*mapper接口的动态代理注册中心*/
  protected final MapperRegistry mapperRegistry = new MapperRegistry(this);

  /*mapper文件中增删改查操作的注册中心*/
  protected final Map<String, MappedStatement> mappedStatements = new StrictMap<>("Mapped Statements collection");

  /*mapper文件中配置cache节点的 二级缓存*/
  protected final Map<String, Cache> caches = new StrictMap<>("Caches collection");

  /*mapper文件中配置的所有resultMap对象  key为命名空间+ID*/
  protected final Map<String, ResultMap> resultMaps = new StrictMap<>("Result Maps collection");
  protected final Map<String, ParameterMap> parameterMaps = new StrictMap<>("Parameter Maps collection");
}

  特别注意的是 Configuration 对象在 MyBatis 中是单例的,生命周期是应用级的,换句话说只要 MyBatis 运行 Configuration 对象就会独一无二的存在;

 

posted @ 2021-11-13 23:57  cqzaier  阅读(60)  评论(0)    收藏  举报