Skip to content

无需任何注解和配置,解决native-image编译运行问题#7017

Open
xiaochenxt wants to merge 5 commits into
baomidou:3.0from
xiaochenxt:native-image
Open

无需任何注解和配置,解决native-image编译运行问题#7017
xiaochenxt wants to merge 5 commits into
baomidou:3.0from
xiaochenxt:native-image

Conversation

@xiaochenxt

Copy link
Copy Markdown

新增mybatis-plus-spring-boot-native-image模块,适配springboot3和springboot4

@YunyuVv

YunyuVv commented Apr 8, 2026

Copy link
Copy Markdown

这个能合并吗? 需要这个功能

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

该 PR 新增 mybatis-plus-spring-boot-native-image 模块,通过 Spring AOT RuntimeHints + GraalVM Feature/资源注册,目标是在无需额外注解与配置的情况下,解决 MyBatis / MyBatis-Plus 在 native-image 编译与运行中的反射、资源与代理问题,并同时适配 Spring Boot 3/4 的 starter 依赖链。

Changes:

  • 新增 mybatis-plus-spring-boot-native-image 模块:提供 AutoConfiguration、RuntimeHintsRegistrar、GraalVM Feature 以及资源配置文件。
  • 将 native-image 模块作为 api 依赖引入 mybatis-plus-spring-boot3-startermybatis-plus-spring-boot4-starter
  • settings.gradlemybatis-plus-bom 中注册/纳入该新模块。

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
spring-boot-starter/mybatis-plus-spring-boot4-starter/build.gradle 为 Boot4 starter 增加 native-image 模块依赖
spring-boot-starter/mybatis-plus-spring-boot3-starter/build.gradle 为 Boot3 starter 增加 native-image 模块依赖
spring-boot-starter/mybatis-plus-spring-boot-native-image/build.gradle 定义新模块的编译版本与依赖(含 nativeimage / 测试依赖)
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/java/com/baomidou/mybatisplus/aot/MyBatisPlusNativeImageConfiguration.java AOT 期间处理 MapperFactoryBean、注册反射/代理/关联类型
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/java/com/baomidou/mybatisplus/aot/MybatisPlusFeature.java GraalVM Feature:注册序列化、反射、资源与代理相关配置
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/java/com/baomidou/mybatisplus/aot/MyBaitsRuntimeHintsRegistrar.java RuntimeHintsRegistrar:注册 XML 资源 hints
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/java/com/baomidou/mybatisplus/aot/FeatureUtils.java native-image hosted API 注册辅助工具
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/java/com/baomidou/mybatisplus/aot/CollectUtils.java 类/资源扫描与收集工具(Feature/AOT 使用)
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/java/com/baomidou/mybatisplus/aot/AotUtils.java Spring RuntimeHints 注册辅助工具
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports 导出 AutoConfiguration
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/resources/META-INF/spring/aot.factories 注册 RuntimeHintsRegistrar
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/main/resources/META-INF/native-image/com.baomidou/mybatis-plus-spring-boot-native-image/native-image.properties 配置 native-image --features
spring-boot-starter/mybatis-plus-spring-boot-native-image/src/test/java/RuntimeHintsRegistrarTest.java 新增 RuntimeHintsRegistrar 基础测试(当前无断言)
settings.gradle include 新模块
mybatis-plus-bom/build.gradle BOM 增加新模块依赖声明

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@xiaochenxt

Copy link
Copy Markdown
Author

这个模块的代码不参与运行时,只在spring-boot:process-aot和native-image编译期间生效,不会影响任何业务代码,没必要搞那么谨慎

@xiaochenxt

Copy link
Copy Markdown
Author

这个能合并吗? 需要这个功能

我发布过dc-spring-boot-native-image,你可以在maven仓库搜,0.1开头的版本是springboot3的,0.4开头的版本是springboot4的,除了mybatis,还支持了awt相关的字体、图片、jpa、caffeine等。原先编译后运行报错的,引入后大多都可以解决

@KeJemas

KeJemas commented Jun 5, 2026

Copy link
Copy Markdown

遇到同样问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants