baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.35k stars 4.31k forks source link

SpringBoot3 AOT 编译报错 #5358

Closed zhaobo-98 closed 1 year ago

zhaobo-98 commented 1 year ago

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

3.5.3.1

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

image

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

mvn clean package -Pnative

报错信息

zhaobo-98 commented 1 year ago

https://github.com/mybatis/mybatis-3/issues/2858

BOFA1ex commented 1 year ago

https://github.com/mybatis/parent/blob/mybatis-parent-37/pom.xml mybatis-parent#37 has already set compile-args with -parameters.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>${compiler.plugin}</version>
  <configuration>
    <parameters>true</parameters>
    <!-- Slightly faster builds, see https://issues.apache.org/jira/browse/MCOMPILER-209 -->
    <useIncrementalCompilation>false</useIncrementalCompilation>
  </configuration>
</plugin>

u could declare mybatis#3.5.13 both with the latest mybatis-plus version.

<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.5.13</version>
</dependency>
yy306525121 commented 1 year ago

这个报错可以参考这个链接解决https://github.com/mybatis/spring-boot-starter/wiki/Quick-Start-for-building-native-image,

但是只要一引入mybatis-plus还是会报错,只能先不用Mybatis-plus了

zieglar commented 1 year ago

关注后续

weichenhk commented 1 year ago

报这个错可以参考这个链接解决https://github.com/mybatis/spring-boot-starter/wiki/Quick-Start-for-building-native-image,

但是只要一引入mybatis-plus还是会报错,只能先不用Mybatis-plus了

我尝试后,通过mybatis提供的这个方案,在使用mybatis-spring-boot-starter时可以实现使用native image的编译和运行。 替换为mybatis-plus-boot-starter后可以编译,运行报错。感觉跟使用了反射有关。运行查询方法错误部分内容如下: image

之后使用跟踪代理收集元数据。其中提供的说明和代码示例。生成元数据之后再通过mvnw -Pnative native:compile编译为native image,可以正常运行。我只实现了一个查询方法,没有进行更多测试。 元数据中的文件reflect-config.json中应该是以下内容起到了作用: image

这个是我目前找到的可以在使用mybatis-plus时实现native image的方法。希望有帮助。

yy306525121 commented 1 year ago

报这个错可以参考这个链接解决https://github.com/mybatis/spring-boot-starter/wiki/Quick-Start-for-building-native-image, 但是只要一引入mybatis-plus还是会报错,只能先不用Mybatis-plus了

我尝试后,通过mybatis提供的这个方案,在使用mybatis-spring-boot-starter时可以实现使用native image的编译和运行。 替换为mybatis-plus-boot-starter后可以编译,运行报错。感觉跟使用了反射有关。运行查询方法错误部分内容如下: image

之后使用跟踪代理收集元数据。其中提供的说明和代码示例。生成元数据之后再通过mvnw -Pnative native:compile编译为native image,可以正常运行。我只实现了一个查询方法,没有进行更多测试。 元数据中的文件reflect-config.json中应该是以下内容起到了作用: image

这个是我目前找到的可以在使用mybatis-plus时实现native image的方法。希望有帮助。

好的好的, 万分感谢, 我抽空试一下

wssy001 commented 1 year ago

升级mybatis-plus-boot-startermybatis相关的版本,项目中引入MyBatisNativeConfiguration ,至此就能顺利编译项目。 如需使用BaseMapper或者IService提供的CRUD方法,还需要手动配置一下mybatis plus中一些接口的jdk代理与相关类的反射,这些操作用Tracing Agent暂时不能收集。 参考的pom.xml

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.3.1</version>
    <exclusions>
        <exclusion>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>3.0.2</version>
</dependency>
shihaoH commented 1 year ago

@wssy001 请问有哪些接口和类需要配置呢。。谢谢大佬

wssy001 commented 1 year ago

@wssy001 请问有哪些接口和类需要配置呢。。谢谢大佬

@shihaoH 可以参考这个discussion

nieqiurong commented 1 year ago

5527 统一至此处讨论