当前位置: 首页 > 知识库问答 >
问题:

带有micronaut和aws sdk-v2的GraalVM本地映像

卫鸿朗
2023-03-14

我在使用micronaut和aws SDK-v2构建GraalVM本机映像时遇到了一个问题。在详细说明错误之前,我想要注意的是,在使用sdk-v2之前,本机映像是正确构建的。

一旦我更新到aws sdk-v2(通过micronaut依赖项as):

...
implementation "io.micronaut.aws:micronaut-aws-sdk-v2:2.0.2"
...

我在试图构建图像时出错了

Fatal error:java.lang.NoSuchMethodError
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:603)
    at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
    at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:480)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:349)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:508)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:114)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:537)
Caused by: java.lang.NoSuchMethodError: 'void io.micronaut.core.graal.AutomaticFeatureUtils.initializeAtBuildTime(org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess, java.lang.String)'
    at io.micronaut.aws.sdk.v2.graal.AwsSdkAutomaticFeature.beforeAnalysis(AwsSdkAutomaticFeature.java:41)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:693)
    at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:70)
    at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:693)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:555)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:468)
    at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Error: Image build request failed with exit status 1
com.oracle.svm.driver.NativeImage$NativeImageError: Image build request failed with exit status 1
    at com.oracle.svm.driver.NativeImage.showError(NativeImage.java:1558)
    at com.oracle.svm.driver.NativeImage.build(NativeImage.java:1308)
    at com.oracle.svm.driver.NativeImage.performBuild(NativeImage.java:1269)
    at com.oracle.svm.driver.NativeImage.main(NativeImage.java:1228)
    at com.oracle.svm.driver.NativeImage$JDK9Plus.main(NativeImage.java:1740)
...

我的假设是micronaut一定在内部做了一些反思,这使得构建过程失败。我添加了以下json文件来设置反射配置

[
  {
    "name" : "io.micronaut.core.graal.AutomaticFeatureUtils",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true
  },
  {
    "name":"io.micronaut.core.graal.AutomaticFeatureUtils",
    "methods":[{"name":"initializeAtBuildTime","parameterTypes":["org.graalvm.nativeimage.hosted.Feature$BeforeAnalysisAccess","java.lang.String[]"] }]
  }
]

共有1个答案

韩宜春
2023-03-14

此错误与反射无关。

Feature和AutomaticFeature是GraalVM本机映像概念,允许对本机iamge进行编程配置,更多细节可以在Javadoc中找到,例如:https://github.com/oracle/graal/blob/master/sdk/src/org.GraalVM.nativeImage/src/org/GraalVM/nativeImage/hosted/Feature.java#l59

您显示的错误发生在图像生成期间,这是一个正常的java过程,不需要配置反射等,这些是运行时行为的配置。

错误说明awssdkautomaticfeature(source尝试调用void io.micronaut.core.graal.automaticfeatureutils.initializeatBuildTime(org.graalvm.nativeImage.hosted.feature$beforeanalysisAccess,java.lang.string))但是没有这样的方法。

 类似资料: