当我使用 Docker 启动 Spring Boot 3.0.0 的原生映像 spring-boot-starter-web 时,它会显示如下奇怪的日志消息:
:: Spring Boot:: (v3.0.0)
%PARSER_ERROR[d]%PARSER_ERROR[p] 1 --- [%PARSER_ERROR[t]]%PARSER_ERROR[logger]:%PARSER_ERROR[m]%PARSER_ERROR[n]%PARSER_ERROR[d]%PARSER_ERROR[p]1 --- [%PARSER_ERROR[t]]%PARSER_ERROR[logger]:%PARSER_ERROR[m]%PARSER_ERROR[n]%PARSER_ERROR[d]%PARSER_ERROR[p]1---
在我尝试依赖spring-boot-starter-webflux之前,本机映像的构建失败,错误为:com.oracle.gral.pointsto.constraints.UnsupportedFeatureException:映像堆中不允许有ch.qos.logback.classic.Logger的实例
使用Spring Orializr,我生成了一个新项目:
然后我用Maven“mvn-p native spring-boot:build-Image”构建原生映像。
我曾期望,原生映像只适用于新的Spring版本的简单配置,就像我在这里所做的那样。是我遗漏了什么,还是Spring Boot 3.0.0在支持原生映像方面有大问题?
当我问这个问题的时候,Spring Initializr还没有为Spring Boot 3.0.0提供(插件)依赖“GraalVM原生支持”。
现在这种依赖性是可用的。正如在SpringOne活动上确认的那样,必须使用它。添加后,提到的错误不会出现。Maven配置中最少需要的部分是:
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
您需要确保在构建插件中添加元数据目标的可达性,请参阅github问题
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<metadataRepository>
<enabled>true</enabled>
</metadataRepository>
<requiredVersion>22.3</requiredVersion>
</configuration>
<executions>
<execution>
<id>add-reachability-metadata</id>
<goals>
<goal>add-reachability-metadata</goal>
</goals>
</execution>
</executions>
</plugin>