How mybatis/spring-boot-starter works
And delineate the key modules
• Auto‑Configuration Module: The “mybatis-spring-boot-autoconfigure” directory contains the core auto‑configuration logic. It defines components (like MyBatisAutoConfiguration, ConfigurationCustomizer, MybatisProperties, etc.) that are wired into the Spring Boot startup via spring.factories and additional metadata in the META-INF directories.
• Starter Module: In “mybatis-spring-boot-starter” you have the module that acts as the entry point (a “starter”) for applications to easily integrate MyBatis. This module depends on the auto‑configuration module and exposes it to end users.
• Test & Test‑Autoconfigure Modules: “mybatis-spring-boot-starter-test” and “mybatis-spring-boot-test-autoconfigure” provide support for testing your MyBatis integrations and demonstrate proper configurations.
• Samples: The “mybatis-spring-boot-samples” folder contains several sub‑modules (annotation, freemarker, groovy, kotlin, thymeleaf, velocity, war, web, xml, etc.) that illustrate various ways to use MyBatis in a Spring Boot environment. They help illustrate usage patterns and validate that the starter works as expected in different scenarios.
• Build and Configuration Infrastructure: The project root itself holds configuration files for Maven, CI/CD pipelines (inside .github/workflows), licensing, and formatting. These ensure consistency and quality across modules.
Relationships and Data Flows
• Input Flow: A Spring Boot application starts up and (via Spring Boot’s auto‑configuration mechanism) loads the auto‑configuration classes from the “mybatis-spring-boot-autoconfigure” module.
• Integration: The auto‑configuration module reads external properties (e.g., via MybatisProperties) and creates/injects beans such as SqlSessionFactoryBeanCustomizer, using Spring’s dependency injection mechanism.
• Starter Role: The starter module acts as the facade, bundling the necessary auto‑configuration and in some cases providing default dependencies that the Spring Boot application will consume.
• Testing: The test modules simulate scenarios and use test-specific configurations to ensure that the auto‑configuration works as intended. There is an interaction between the test modules and the framework’s auto-configuration testing support.
• Samples: The samples demonstrate complete application examples. They connect the user interface (if any) or REST endpoints with the data layer that uses MyBatis, thereby showcasing the typical lifecycle and integration with Spring Boot applications.
Architectural Patterns and Design Principles
• Modular Design: The separation into auto‑configuration, starter, testing, and samples helps ensure that the core functionality is decoupled from demonstration projects and testing utilities.
• Convention over Configuration: The use of Spring Boot auto‑configuration leverages Spring’s “magic” where properties and metadata (e.g., in spring.factories) reduce the need for manual wiring.
• Dependency Injection and Inversion of Control: The design takes full advantage of Spring’s container to manage component lifecycles and dependencies.
• Extensibility: The design provides extension points (e.g., ConfigurationCustomizer, SqlSessionFactoryBeanCustomizer) so that users can override or extend default behavior.
Relevant Technologies
• MyBatis: The underlying data mapper.
• Spring Boot: Provides the auto-configuration and dependency injection framework.
• Maven: The build tool organizing the multi-module structure.
• Testing Frameworks: JUnit and spring-boot-test support modules for integration and unit testing.