Skip to main content

MyBatis 3.5 Source Analysis Part 1: Configuration and Mapper Proxies

· One min read
Apache Wangye
Software developer and technical writer

MyBatis startup converts XML, annotations, type aliases, handlers, environments, and mapper definitions into a central Configuration object.

SqlSessionFactoryBuilder parses configuration and creates a DefaultSqlSessionFactory. Opening a session creates an Executor and wraps it in DefaultSqlSession, which exposes select, insert, update, delete, commit, and rollback operations.

Mapper interfaces do not require handwritten implementations. MapperRegistry records them, and MapperProxyFactory creates a JDK dynamic proxy. A method invocation reaches MapperProxy, resolves a cached MapperMethod, derives the mapped statement ID from the interface and method name, converts arguments, and delegates to SqlSession.

Mapped statements hold SQL source, command type, parameter map, result map, cache settings, and other execution metadata. Understanding their registration explains common errors such as missing statements, duplicate IDs, incorrect namespaces, and return-type mismatches.

When reading the source, follow one simple mapper call end to end and record object ownership and lifecycle rather than reading packages in isolation.

Page views: --

Total views -- · Visitors --