Mybatis MissingParametersCompilerArgumentException

Last Modified: 2023/04/29

前言

最近尝试将 spring boot 项目升级到 3.0,并尝试将其打包成 native 镜像,升级的过程并不是很折腾,网上的教程也很多,升级完成之后就是打包了,这个过程中出现了一个 mybatis 问题的小插曲,这里记录下,供大家参考。

打包 native 镜像

spring boot 3.0 对 native 支持是内置的,我们不需要再引入 spring-native 和 spring-aot-maven-plugin。 打包的方法相当简单:

mvn clean -Pnative spring-boot:build-image

这里有必要说明下,打包的命令固然简单,但是想成功打出 native 包却没那么简单。只有你实际体验了才能感受到这个过程有多坑。也许你最大的问题是网络问题!

当我运行上面的命令后,报错信息如下:

Exception in thread "main" org.springframework.boot.context.properties.bind.MissingParametersCompilerArgumentException: Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it:
	org.apache.ibatis.parsing.XNode
	org.apache.ibatis.mapping.ResultFlag
	org.apache.ibatis.builder.annotation.MethodResolver
	org.apache.ibatis.builder.CacheRefResolver
	org.apache.ibatis.builder.ResultMapResolver

	at org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar.registerHints(BindableRuntimeHintsRegistrar.java:91)
	at org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor$ConfigurationPropertiesReflectionHintsContribution.applyTo(ConfigurationPropertiesBeanFactoryInitializationAotProcessor.java:70)

出现上面问题的原因是由于我的项目使用的 mybatis 的版本为 3.5.9,实际上这是一个已知的 mybatis 问题,mybatis 3.5.12 已经解决了该问题,我们只要将 Mybatis 升级到 3.5.12 即可。

可以看到 mybatis 3.5.12 的 release note 中 https://github.com/mybatis/mybatis-3/releases/tag/mybatis-3.5.12 有一条:

Uses parameters option for compiler now (needed by spring boot 3) (for reflection needs)

有问题吗?点此反馈!

温馨提示:反馈需要登录