Fix MapperFactoryBean constructor argument for AOT#1235
Fix MapperFactoryBean constructor argument for AOT#1235DragonFSKY wants to merge 1 commit intomybatis:3.0.xfrom
Conversation
|
I also checked the same code path against current Using After bypassing the separate duplicate-scan issue with Applying the same fix changes the generated constructor argument from the mapper interface name string to the mapper interface class literal, for example: beanDefinition.getConstructorArgumentValues()
.addGenericArgumentValue(DictionaryMapper.class);With that change, the same AOT run succeeds and prints: So this PR targets |
052ddfd to
4d041a1
Compare
Use the resolved mapper interface class as the constructor argument when the configured MapperFactoryBean expects a Class-based constructor. Keep the existing String constructor argument for custom MapperFactoryBean implementations that support String-compatible constructors to preserve backward compatibility.
This PR fixes an AOT/native runtime failure where
MapperFactoryBeantries to resolveClass<?>as an autowired dependency.ClassPathMapperScannercurrently registers the mapper interface constructor argument as a class nameString. This works in the regular JVM path because Spring can convert the value to theClass<?>constructor argument required byMapperFactoryBean.In the AOT/native path, the generated bean supplier uses the
MapperFactoryBean(Class<?>)constructor, but the bean definition still contains the mapper interface constructor argument as aString. The generated supplier does not appear to apply the sameStringtoClass<?>conversion, so native runtime fails with:This change uses the resolved mapper interface
Class<?>as the constructor argument only when the configuredMapperFactoryBeanhas a single-argument constructor that can acceptClass<?>and does not have a single-argument constructor that can acceptString.This preserves the existing
Stringconstructor argument behavior for customMapperFactoryBeanimplementations that supportString-compatible constructors.Regression tests were added for the default
MapperFactoryBean, a custom factory with aStringconstructor, and a custom factory with bothStringandClass<?>constructors.The same constructor argument registration path also exists on
master, so this fix may need to be forward-ported if maintainers prefer to keep the branches aligned.Tested with:
./mvnw -Dtest=MapperScannerConfigurerTest -Dformatter.skip=true -Dwhitespace.skip=true -Dlicense.skip=true -Djacoco.skip=true -Drewrite.skip=true testAlso verified with a native reproduction project:
https://github.com/DragonFSKY/mybatis-3675-repro
Refs #929.
Refs mybatis/mybatis-3#3675.