使用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
相关产品推荐
相关产品推荐

