Closed tuhe32 closed 1 year ago
mvn -Pnative clean native:compile 跑不起来, 看异常感觉和classLoader有关...先自己排查看下也
- Can you create a git of this zip at github.com so I can verify it via codespaces?
- Please format your Error Log via markdown, which seems to be missing HikariCP’s GraalVM Reachability Metadata.
测试用例已经放到 git 上。https://github.com/tuhe32/boot-native.git mvn -Pnative clean native:compile 是成功的。 启动项目时报错。
@tuhe32 Handled at https://github.com/linghengqian/boot-native/commit/a58b8d91008aef1a62787795e2de5da90a6f7714 .
It seems you don't know how to use org.springframework.boot:spring-boot-maven-plugin
-- so I refactored the pom.xml
and created two Maven Profile of nativeTest
and generateMetadata
to directly expose the Error Log.
You are using org.graalvm.sdk:graal-sdk
at the classpath level, which is very dangerous behavior because the API of graal-sdk
is not stable and its public API is usually used for Maven Plugin/Gradle Plugin/sbt Plugin. Please directly use JSON to define GraalVM Reachability Metadata, or use the relevant classes of Spring Framework to complete the definition of GraalVM Reachability Metadata. This additionally results in a buildArg that requires -H:+AllowDeprecatedBuilderClassesOnImageClasspath
.
This appears to be a bug involving com.baomidou.mybatisplus.core.toolkit.LambdaUtils
. What I mean is that Mybatis Plus doesn't seem to work under GraalVM Native Image. This commit also exposes that the Dynamic Datasource may be missing some JSON entries, but because of the issues with Mybatis Plus, I don't see the need to try to submit a PR.
Call @huayanYu , it looks like you are a committer for Mybatis Plus, do you have any more information?
Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: java.lang.ClassNotFoundException: com.example.bootnative.BootNativeApplication$$Lambda$0e4dae6cce3633a42432312a352810f4c99affcf
com.baomidou.mybatisplus.core.toolkit.support.SerializedLambda.extract(SerializedLambda.java:58)
com.baomidou.mybatisplus.core.toolkit.LambdaUtils.extract(LambdaUtils.java:67)
com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper.getColumnCache(AbstractLambdaWrapper.java:128)
com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper.columnToString(AbstractLambdaWrapper.java:66)
com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper.lambda$columnsToString$0(AbstractLambdaWrapper.java:57)
[...]
Fixed in https://github.com/linghengqian/boot-native/commit/50b6def6b93b8e43663f563469ffa2669286e185 , I just noticed com.example.bootnative.LambdaRegistrationFeature
.🤣 I still would not encourage carrying GraalVM Feature classes on the classpath. This is very dangerous behavior with new versions of the GraalVM compiler.
In the reproduced git, I did not write additional extra-filter.json
to filter the third-party library JSON. You can refer to https://github.com/baomidou/dynamic-datasource/blob/v4.2.0/native-image/extra-filter.json.
It looks like there are some JSON entries available for adding on the baomidou/dynamic-datasource side. @huayanYu Please assign this issue to me.
lambdaCapturingTypes
sets the GraalVM Reachability Metadata specific to your project. This seems to involve a bug in GraalVM CE 23.1.1 For JDK 21.0.1/GraalVM Tracing Agent
, which does not collect the contents of lambdaCapturingTypes
.So I confirmed the real missing GraalVM Reachability Metadata at https://github.com/linghengqian/boot-native/commit/34ff8ce857b09e3993be5bf414878e5b11291089. This question comes from https://github.com/oracle/graalvm-reachability-metadata/blob/0.3.5/metadata/com.zaxxer/HikariCP/5.0.1/reflect-config.json , not baomidou/dynamic-datasource .
[
{
"condition":{"typeReachable":"com.zaxxer.hikari.HikariConfig"},
"name":"com.zaxxer.hikari.HikariConfig",
"methods":[{"name":"<init>","parameterTypes":[] }]
}
]
@tuhe32 I think you should open a related issue and PR at https://github.com/oracle/graalvm-reachability-metadata and provide a smaller unit test.
I don't think baomidou/dynamic-datasource should actively host HikariCP's GraalVM Reachability Metadata unless many people ask for it. @huayanYu What do you think?
This issue can be closed.
说实话,我完全不了解GraalVM.... mybatis-plus支持springboot3的相关issue https://github.com/baomidou/mybatis-plus/issues/5527
There is a factual error in https://github.com/baomidou/mybatis-plus/issues/5527#issuecomment-1758863971 , user should use JSON definition instead of introducing org.graalvm.sdk:graal-sdk
, graal-sdk
has been refactored starting with GraalVM 23.1.0, which means earlier versions of graal-sdk
are completely obsolete.
The behavior of defining GraalVM Reachability Metadata for Mybatis through code does not involve conditional entries, which does not meet the requirements of GraalVM Reachability Metadata, which means that this class is incomplete in class introspection.
But in general, the current issue only concerns the missing GraalVM Reachability Metadata of HikariCP, which has nothing to do with Dynamic Datasource.
@linghengqian 引入 graal-sdk
纯属是无奈之举 正如你前文提及的,Tracing Agent
无法收集到lambdaCapturingTypes
内容;而且Spring
团队也不重视,之前有开发者提了feat
,要求适配graal-sdk
中org.graalvm.nativeimage.hosted.RuntimeSerialization#registerLambdaCapturingClass
这一方法,结果还被当成了无意义提案。
@linghengqian 引入
graal-sdk
纯属是无奈之举 正如你前文提及的,Tracing Agent
无法收集到lambdaCapturingTypes
内容;而且Spring
团队也不重视,之前有开发者提了feat
,要求适配graal-sdk
中org.graalvm.nativeimage.hosted.RuntimeSerialization#registerLambdaCapturingClass
这一方法,结果还被当成了无意义提案。
{
"types":[
],
"lambdaCapturingTypes":[
{
"name":"com.example.bootnative.BootNativeApplication"
}
],
"proxies":[
]
}
所以和动态数据源无关是吧.
所以和动态数据源无关是吧.
不明觉厉,closed.
所以和动态数据源无关是吧.
- This issue has nothing to do with dynamic datasource unless we host the GraalVM Reachability Metadata of a third-party library like shardingsphere. Reference https://github.com/apache/shardingsphere/tree/3aff42fbe6909674d7582e098c9c1a453a63e86d/infra/reachability-metadata/src/main/resources/META-INF/native-image .
- The JSON for these third-party libraries is more suitable for submission to https://github.com/oracle/graalvm-reachability-metadata . Users can add it by themselves.
在你的例子里面,可以跑起来,但是我要如何在编译的时候不报错呢
所以和动态数据源无关是吧.
- This issue has nothing to do with dynamic datasource unless we host the GraalVM Reachability Metadata of a third-party library like shardingsphere. Reference https://github.com/apache/shardingsphere/tree/3aff42fbe6909674d7582e098c9c1a453a63e86d/infra/reachability-metadata/src/main/resources/META-INF/native-image .
- The JSON for these third-party libraries is more suitable for submission to https://github.com/oracle/graalvm-reachability-metadata . Users can add it by themselves.
在你的例子里面,可以跑起来,但是我要如何在编译的时候不报错呢
Please fill it out carefully, or it will be closed. 请认真填写,不然会直接关闭。
Enviroment
Version info: 'GraalVM 22.3.0 Java 17 CE' Java version info: '17.0.5+8-jvmci-22.3-b08' C compiler: cc (apple, x86_64, 13.1.6)
JDK Version(required): '17.0.5+8-jvmci-22.3-b08' SpringBoot Version(required): 3.1.4 dynamic-datasource-spring-boot-starter Version(required): 4.2.0 druid Version(optional):
Describe what happened
项目用了HikariCP连接池 用mvn -Pnative clean native:compile 打包是成功的。启动报错:
Expected Result:
Actual Result:
If there is an exception,or aop invalid,please attach the exception trace:
Steps to reproduce
测试用例:
Step 1 测试用例地址 https://github.com/tuhe32/boot-native.git
Step 2
Step 3