UnsupportedFeatureException:在图像堆中找到 ...NestedFileSystemProvider 类型的对象

问题描述 投票:0回答:1

我正在使用

graalvm-jdk-22.0.1+8.1
构建
spring-boot-starter
本机容器映像,但出现以下错误:

[INFO]     [creator]     ================================================================================
[INFO]     [creator]     GraalVM Native Image: Generating 'com.example.demo.DemoApplication' (executable)...
[INFO]     [creator]     ================================================================================
[INFO]     [creator]     For detailed information and explanations on the build output, visit:
[INFO]     [creator]     https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]     [1/8] Initializing...                                            (9.2s @ 0.13GB)
[INFO]     [creator]      Java version: 22.0.1+10, vendor version: Liberica-NIK-24.0.1-1
[INFO]     [creator]      Graal compiler: optimization level: 2, target machine: x86-64-v3
[INFO]     [creator]      C compiler: gcc (linux, x86_64, 11.4.0)
[INFO]     [creator]      Garbage collector: Serial GC (max heap size: 80% of RAM)
[INFO]     [creator]      2 user-specific feature(s):
[INFO]     [creator]      - com.oracle.svm.thirdparty.gson.GsonFeature
[INFO]     [creator]      - org.springframework.aot.nativex.feature.PreComputeFieldFeature
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]      2 experimental option(s) unlocked:
[INFO]     [creator]      - '-H:Name' (alternative API option(s): -o com.example.demo.DemoApplication; origin(s): command line)
[INFO]     [creator]      - '-H:+StaticExecutableWithDynamicLibC' (origin(s): command line)
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]     Build resources:
[INFO]     [creator]      - 8.83GB of memory (56.9% of 15.53GB system memory, determined at start)
[INFO]     [creator]      - 8 thread(s) (100.0% of 8 available processor(s), determined at start)
[INFO]     [creator]     SLF4J(W): No SLF4J providers were found.
[INFO]     [creator]     SLF4J(W): Defaulting to no-operation (NOP) logger implementation
[INFO]     [creator]     SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
[INFO]     [creator]     [2/8] Performing analysis...  []                                (51.5s @ 0.64GB)
[INFO]     [creator]         7,254 reachable types   (79.7% of    9,106 total)
[INFO]     [creator]         8,510 reachable fields  (48.4% of   17,574 total)
[INFO]     [creator]        30,520 reachable methods (51.2% of   59,658 total)
[INFO]     [creator]         2,514 types,   131 fields, and 1,782 methods registered for reflection
[INFO]     [creator]     
[INFO]     [creator]     Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: An object of type 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' was found in the image heap. This type, however, is marked for initialization at image run time for the following reason: classes are initialized at run time by default.
[INFO]     [creator]     This is not allowed for correctness reasons: All objects that are stored in the image heap must be initialized at build time.
[INFO]     [creator]     
[INFO]     [creator]     You now have two options to resolve this:
[INFO]     [creator]     
[INFO]     [creator]     1) If it is intended that objects of type 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' are persisted in the image heap, add 
[INFO]     [creator]     
[INFO]     [creator]         '--initialize-at-build-time=org.springframework.boot.loader.nio.file.NestedFileSystemProvider'
[INFO]     [creator]     
[INFO]     [creator]     to the native-image arguments. Note that initializing new types can store additional objects to the heap. It is advised to check the static fields of 'org.springframework.boot.loader.nio.file.NestedFileSystemProvider' to see if they are safe for build-time initialization,  and that they do not contain any sensitive data that should not become part of the image.
[INFO]     [creator]     
[INFO]     [creator]     2) If these objects should not be stored in the image heap, you can use 
[INFO]     [creator]     
[INFO]     [creator]         '--trace-object-instantiation=org.springframework.boot.loader.nio.file.NestedFileSystemProvider'
[INFO]     [creator]     
[INFO]     [creator]     to find classes that instantiate these objects. Once you found such a class, you can mark it explicitly for run time initialization with 
[INFO]     [creator]     
[INFO]     [creator]         '--initialize-at-run-time=<culprit>'
[INFO]     [creator]     
[INFO]     [creator]     to prevent the instantiation of the object.
[INFO]     [creator]     
[INFO]     [creator]     If you are seeing this message after upgrading to a new GraalVM release, this means that some objects ended up in the image heap without their type being marked with --initialize-at-build-time.
[INFO]     [creator]     To fix this, include '--initialize-at-build-time=org.springframework.boot.loader.nio.file.NestedFileSystemProvider' in your configuration. If the classes do not originate from your code, it is advised to update all library or framework dependencies to the latest version before addressing this error.
[INFO]     [creator]     
[INFO]     [creator]     The following detailed trace displays from which field in the code the object was reached.
[INFO]     [creator]     Object was reached by
[INFO]     [creator]       manually created constant
[INFO]     [creator]     --------------------------------------------------------------------------------
[INFO]     [creator]         6.1s (9.6% of total time) in 130 GCs | Peak RSS: 1.21GB | CPU load: 6.54
[INFO]     [creator]     ================================================================================
[INFO]     [creator]     Failed generating 'com.example.demo.DemoApplication' after 1m 1s.
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:41 min
[INFO] Finished at: 2024-05-14T13:34:10+02:00
[INFO] ------------------------------------------------------------------------

我也尝试了

--initialize-at-build-time
的建议,但没有运气。

重现步骤:

  1. 前往https://start.spring.io/
  2. 选择:Maven、Java、Spring Boot 3.2.5、Jar 打包和 Java 22。
  3. 添加“GraalVM Native Support”依赖项。
  4. 下载并解压项目。
  5. 奔跑
    ./mvnw -Pnative -DskipTests spring-boot:build-image
  6. 显示以上错误。

关于如何解决该问题并能够使用提供的选项(Java 22、GraalVM JDK)从 Spring Boot 项目构建本机容器映像有什么想法吗?

提前致谢!

spring-boot maven graalvm spring-native java-22
1个回答
0
投票

这是由本机映像构建包中的 bug 引起的。正如其中一条评论中所描述的,您可以通过在您的 pom.xml 中进行一些额外的配置来解决它:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <image>
      <env>
        <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>-H:-AddAllFileSystemProviders</BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
      </env>
    </image>
  </configuration>
</plugin>

© www.soinside.com 2019 - 2024. All rights reserved.