You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用GraalVM Maven插件构建Spring Boot 3本地镜像遇预览功能未启用报错求助

解决方案

你的问题出在运行Spring Boot应用时未启用预览特性:编译阶段已经通过maven-compiler-plugin开启了--enable-preview生成带预览特性的class文件,但使用spring-boot:run启动应用时,JVM参数里缺少该开关,导致无法加载对应类文件。

修改spring-boot-maven-plugin的配置,在jvmArguments中添加--enable-preview:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <jvmArguments>
            --enable-preview
            -agentlib:native-image-agent=config-merge-dir=src/main/resources/META-INF/native-image/
        </jvmArguments>
    </configuration>
</plugin>

修改后重新执行mvn -Pnative spring-boot:run即可解决问题。

补充说明:

  • maven-compiler-plugin的配置保持不变,确保编译阶段生成支持预览特性的class文件;
  • native-maven-plugin中--enable-preview的配置已经正确,后续生成本地镜像时无需额外调整。

内容的提问来源于stack exchange,提问作者Feng Ye

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 10:40:49