Skip to content

Add MyBatis integration module#1921

Merged
sdelamo merged 21 commits into
7.1.xfrom
feat/mybatis-support-815
Jul 7, 2026
Merged

Add MyBatis integration module#1921
sdelamo merged 21 commits into
7.1.xfrom
feat/mybatis-support-815

Conversation

@graemerocher

Copy link
Copy Markdown
Contributor

Summary

  • add a new micronaut-mybatis module that creates MyBatis configuration and session beans from Micronaut datasources
  • cover datasource qualification, customizers, and transaction factory selection with focused tests
  • document the new module and convert the MyBatis guide examples to snippet::-backed Java, Kotlin, and Groovy docs examples

Verification

  • ./gradlew :micronaut-mybatis:test
  • ./gradlew --rerun-tasks publishGuide docs

Resolves #815

@graemerocher graemerocher added the type: enhancement New feature or request label Apr 17, 2026
@graemerocher graemerocher self-assigned this Apr 17, 2026
@graemerocher graemerocher force-pushed the feat/mybatis-support-815 branch from c1fcedc to 071e179 Compare April 17, 2026 07:38
@graemerocher graemerocher changed the base branch from 6.0.x to 7.0.x April 17, 2026 07:38
@graemerocher graemerocher marked this pull request as ready for review April 17, 2026 12:47
@graemerocher graemerocher requested a review from Copilot April 17, 2026 12:48
@github-project-automation github-project-automation Bot moved this to Backlog in 5.0.0-M2 Apr 17, 2026
@graemerocher graemerocher moved this from Backlog to In review in 5.0.0-M2 Apr 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new Micronaut MyBatis integration module and accompanying guide/docs examples to enable automatic MyBatis bean creation from configured JDBC datasources.

Changes:

  • Introduces mybatis module with MyBatisFactory and MyBatisConfigurationCustomizer SPI.
  • Adds focused tests for bean creation, customizer application, and transaction factory fallback/selection.
  • Updates the user guide (TOC + new MyBatis pages) and adds snippet-backed Java/Kotlin/Groovy docs examples.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/docs/guide/toc.yml Adds MyBatis section entries to the SQL guide TOC.
src/main/docs/guide/mybatis/mybatis-session-access.adoc Documents injecting MyBatis runtime beans produced per datasource.
src/main/docs/guide/mybatis/mybatis-customizers.adoc Documents configuration customizers and transaction factory selection.
src/main/docs/guide/mybatis.adoc Adds main MyBatis integration guide page and bean list.
src/main/docs/guide/introduction.adoc Expands introduction with a list of supported integrations (includes MyBatis).
settings.gradle Includes new mybatis Gradle subproject.
mybatis/src/test/java/io/micronaut/configuration/mybatis/support/TestTransactionFactory.java Adds a qualified test transaction factory bean for selection tests.
mybatis/src/test/java/io/micronaut/configuration/mybatis/TestMyBatisConfigurationCustomizer.java Adds a qualified customizer used by tests (mapper registration + settings).
mybatis/src/test/java/io/micronaut/configuration/mybatis/TestMapper.java Adds a small test mapper used by integration tests.
mybatis/src/test/java/io/micronaut/configuration/mybatis/MyBatisFactoryTest.java Adds tests asserting bean creation and fallback behavior.
mybatis/src/main/java/io/micronaut/configuration/mybatis/package-info.java Declares package-level configuration/requirements for the module.
mybatis/src/main/java/io/micronaut/configuration/mybatis/MyBatisFactory.java Implements MyBatis bean creation from Micronaut DataSource beans.
mybatis/src/main/java/io/micronaut/configuration/mybatis/MyBatisConfigurationCustomizer.java Adds SPI for customizing the MyBatis Configuration per datasource.
mybatis/build.gradle Adds Gradle module build + dependencies for the new integration.
gradle/libs.versions.toml Adds managed MyBatis dependency coordinates and version.
docs-examples/mybatis-kotlin/src/test/kotlin/io/micronaut/configuration/mybatis/docs/ReportingRepository.kt Adds Kotlin snippet example for qualified bean injection.
docs-examples/mybatis-kotlin/src/test/kotlin/io/micronaut/configuration/mybatis/docs/InventoryRepository.kt Adds Kotlin snippet example using SqlSessionManager + mapper.
docs-examples/mybatis-kotlin/src/test/kotlin/io/micronaut/configuration/mybatis/docs/InventoryMyBatisCustomizer.kt Adds Kotlin snippet example customizer registering a mapper.
docs-examples/mybatis-kotlin/src/test/kotlin/io/micronaut/configuration/mybatis/docs/InventoryMapper.kt Adds Kotlin snippet mapper interface.
docs-examples/mybatis-kotlin/src/test/kotlin/io/micronaut/configuration/mybatis/docs/Inventory.kt Adds Kotlin snippet model class.
docs-examples/mybatis-java/src/test/java/io/micronaut/configuration/mybatis/docs/ReportingRepository.java Adds Java snippet example for qualified bean injection.
docs-examples/mybatis-java/src/test/java/io/micronaut/configuration/mybatis/docs/InventoryRepository.java Adds Java snippet example using SqlSessionManager + mapper.
docs-examples/mybatis-java/src/test/java/io/micronaut/configuration/mybatis/docs/InventoryMyBatisCustomizer.java Adds Java snippet example customizer registering a mapper.
docs-examples/mybatis-java/src/test/java/io/micronaut/configuration/mybatis/docs/InventoryMapper.java Adds Java snippet mapper interface.
docs-examples/mybatis-java/src/test/java/io/micronaut/configuration/mybatis/docs/Inventory.java Adds Java snippet model record.
docs-examples/mybatis-groovy/src/test/groovy/io/micronaut/configuration/mybatis/docs/ReportingRepository.groovy Adds Groovy snippet example for qualified bean injection.
docs-examples/mybatis-groovy/src/test/groovy/io/micronaut/configuration/mybatis/docs/InventoryRepository.groovy Adds Groovy snippet example using SqlSessionManager + mapper.
docs-examples/mybatis-groovy/src/test/groovy/io/micronaut/configuration/mybatis/docs/InventoryMyBatisCustomizer.groovy Adds Groovy snippet example customizer registering a mapper.
docs-examples/mybatis-groovy/src/test/groovy/io/micronaut/configuration/mybatis/docs/InventoryMapper.groovy Adds Groovy snippet mapper interface.
docs-examples/mybatis-groovy/src/test/groovy/io/micronaut/configuration/mybatis/docs/Inventory.groovy Adds Groovy snippet model class.
README.md Updates repository description and mentions the new MyBatis module in docs.

Comment thread mybatis/src/main/java/io/micronaut/configuration/mybatis/MyBatisFactory.java Outdated
Comment thread mybatis/src/main/java/io/micronaut/configuration/mybatis/MyBatisFactory.java Outdated
Comment thread mybatis/src/main/java/io/micronaut/configuration/mybatis/MyBatisFactory.java Outdated
Comment thread src/main/docs/guide/mybatis/mybatis-customizers.adoc Outdated
@graemerocher

Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Applied the requested review-thread updates in commit a1cce1d: removed incorrect @Parameter usage on non-iteration dependencies in MyBatisFactory, removed explicit connection.commit() in MyBatisFactoryTest, and updated docs wording to @Named. Verified with ./gradlew :micronaut-mybatis:test, ./gradlew -q cM, and ./gradlew -q spotlessCheck (using Java 21).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-3333d316ef795607/dbs/java/working/files-to-index13008035018410833928.list --sourceArchiveDir=/tmp/codeql-scratch-3333d316ef795607/dbs/java/src --outputDir=/tmp/codeql-scratch-3333d316ef795607/dbs/java/trap/java (dns block)
  • ge.micronaut.io
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xmx2048M -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@graemerocher

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 2 commits April 17, 2026 14:34
Co-authored-by: graemerocher <66626+graemerocher@users.noreply.github.com>
Co-authored-by: graemerocher <66626+graemerocher@users.noreply.github.com>

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved by merging origin/7.0.x and fixing the conflict fallout while keeping the MyBatis module/docs wired in. Addressed in 765c396d (with merge commit e506b74c).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-3333d316ef795607/dbs/java/working/files-to-index16677211169254936407.list --sourceArchiveDir=/tmp/codeql-scratch-3333d316ef795607/dbs/java/src --outputDir=/tmp/codeql-scratch-3333d316ef795607/dbs/java/trap/java --global k/_temp/ghcca-node/node/bin/git committer.email (dns block)
  • ge.micronaut.io
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -Xmx2048M -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Comment thread settings.gradle
@radovanradic

Copy link
Copy Markdown
Contributor

The build is running forever, there is the error

io.micronaut.configuration.mybatis.MyBatisFactoryTest doesNotCreateBeansWithoutDataSource() FAILED

java.lang.StackOverflowError

@sdelamo sdelamo removed this from 5.0.0-M2 Apr 21, 2026
@sdelamo sdelamo added this to 5.0.0-M3 Apr 21, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in 5.0.0-M3 Apr 21, 2026
@sdelamo sdelamo removed this from 5.0.0-M3 Apr 29, 2026
@sdelamo sdelamo removed this from 5.0.0 Release May 12, 2026
@sdelamo sdelamo changed the base branch from 7.0.x to 7.1.x July 3, 2026 10:55
sdelamo added 12 commits July 3, 2026 13:03
Update MyBatis configuration creation to resolve the datasource-specific TransactionFactory through BeanLocator, falling back to JdbcTransactionFactory when none is registered.

Also type the SqlSessionManager bean explicitly so it is exposed as SqlSessionManager.
Comment thread mybatis/src/main/java/io/micronaut/configuration/mybatis/package-info.java Outdated
@sonarqubecloud

sonarqubecloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

@sdelamo sdelamo merged commit 7690b2c into 7.1.x Jul 7, 2026
30 checks passed
@sdelamo sdelamo deleted the feat/mybatis-support-815 branch July 7, 2026 09:05
@github-project-automation github-project-automation Bot moved this from Backlog to Done in 5.1.0 Release Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

How about a plugin for mybatis?

6 participants