当前使用版本(必填,否则不予处理)

SpringBoot: 3.2 mybatis-plus-spring-boot3-starter: 3.5.5-SNAPSHOT

该问题是如何引起的?(确定最新版也有问题再提!!!)

该问题应该是升级Spring6.1.1后相关的没有适配,导致的,拜托麻烦解决下^_^

重现步骤(如果有就写完整)

通过测试工程:https://github.com/nieqiurong/mybatis-native-demo.git可以复现,把工程的SpringBoot升级到3.2,mybatis-plus-spring-boot3-starter升级到3.5.5-SNAPSHOT,然后生成镜像,运行时会产生该问题。

报错信息

MyBatis-Plus 关于升级到SpringBoot3.2后,构建Spring Native镜像运行时报错,找不到Mapper问题

Comment From: pigeon2049

+1

Comment From: pigeon2049

就差mybatis-plus解决这个问题就能把项目编译成native了

Comment From: scafel

去掉mp的mybatis-spring 自己更新到3.0.3

Comment From: XuYaoAnansi

去掉mp的mybatis-spring 自己更新到3.0.3

不行,我用的就是3.0.3,正常运行没问题,但是native镜像运行就有问题,不过我觉得应该问题还是在mybatis那边注入@Mapper的时候产生的问题,但是不知道怎么解决

Comment From: stander

跟这个issue情况类似,但是mybatis还没有提供解决方案 https://github.com/mybatis/spring-native/issues/128

Comment From: XuYaoAnansi

跟这个issue情况类似,但是mybatis还没有提供解决方案 mybatis/spring-native#128

是的,我也找到这个issue,但是没啥动静,智能等mybatis那边了吗?

Comment From: XuYaoAnansi

我解决了这个问题,应该是在Spring6.1之前对有参数注入和无参注入做了忽略,现在要强匹配了,加上代码 ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(mapperInterface); beanDefinition.setConstructorArgumentValues(constructorArgumentValues); 就可以了

Comment From: nieqiurong

我解决了这个问题,应该是在Spring6.1之前对有参数注入和无参注入做了忽略,现在要强匹配了,加上代码 ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(mapperInterface); beanDefinition.setConstructorArgumentValues(constructorArgumentValues); 就可以了

可以,按你的方式更新一下.

Comment From: stander

按照上述方法修改了MybatisNativeConfiguration,现在可以启动,但是查询时出现以下报错 NoSuchMethodException: org.apache.ibatis.type.EnumTypeHandler

Comment From: pudisdo

我解决了这个问题,应该是在Spring6.1之前对有参数注入和无参注入做了忽略,现在要强匹配了,加上代码 ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(mapperInterface); beanDefinition.setConstructorArgumentValues(constructorArgumentValues); 就可以了

按照你的方法修改,成功解决了。谢谢。

Comment From: XuYaoAnansi

NoSuchMethodException

NoSuchMethodException这种异常在native可以尝试hint下,不是这个issue提出的问题

Comment From: choubuzhaole

我解决了这个问题,应该是在Spring6.1之前对有参数注入和无参注入做了忽略,现在要强匹配了,加上代码 ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(mapperInterface); beanDefinition.setConstructorArgumentValues(constructorArgumentValues); 就可以了

能给我 一个完整的示例吗,谢谢

我使用以下调整未能解决这个问题 ` // 获取所有带有 @Mapper 注解的类

        @Autowired
        private GenericBeanDefinition beanDefinition;


    String[] mapperBeanNames = applicationContext.getBeanNamesForAnnotation(Mapper.class);
    // 使用 ConstructorArgumentValues 注入所有 mapper 实现类
    ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues();
    for (String beanName : mapperBeanNames) {
        constructorArgs.addGenericArgumentValue(new RuntimeBeanReference(beanName));
    }
    beanDefinition.setConstructorArgumentValues(constructorArgs);

`

Comment From: amwyyyy

我解决了这个问题,应该是在Spring6.1之前对有参数注入和无参注入做了忽略,现在要强匹配了,加上代码 ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(mapperInterface); beanDefinition.setConstructorArgumentValues(constructorArgumentValues); 就可以了

能给我 一个完整的示例吗,谢谢

我使用以下调整未能解决这个问题 ` // 获取所有带有 @Mapper 注解的类

``` @Autowired private GenericBeanDefinition beanDefinition;

String[] mapperBeanNames = applicationContext.getBeanNamesForAnnotation(Mapper.class); // 使用 ConstructorArgumentValues 注入所有 mapper 实现类 ConstructorArgumentValues constructorArgs = new ConstructorArgumentValues(); for (String beanName : mapperBeanNames) { constructorArgs.addGenericArgumentValue(new RuntimeBeanReference(beanName)); } beanDefinition.setConstructorArgumentValues(constructorArgs); ```

`

private void resolveMapperFactoryBeanTypeIfNecessary(RootBeanDefinition beanDefinition) {
      if (!beanDefinition.hasBeanClass() || !MapperFactoryBean.class.isAssignableFrom(beanDefinition.getBeanClass())) {
        return;
      }
      if (beanDefinition.getResolvableType().hasUnresolvableGenerics()) {
        Class<?> mapperInterface = getMapperInterface(beanDefinition);
        if (mapperInterface != null) {
            ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
            constructorArgumentValues.addGenericArgumentValue(mapperInterface);
            beanDefinition.setConstructorArgumentValues(constructorArgumentValues);
            beanDefinition.setConstructorArgumentValues(constructorArgumentValues);
            beanDefinition.setTargetType(ResolvableType.forClassWithGenerics(beanDefinition.getBeanClass(), mapperInterface));
        }
      }
    }