Spring 引导 Docker Spring R2DBC 应用程序在 Java 16 上的本机映像在不受支持的方法上失败

Spring Boot Docker Native image of Spring R2DBC application on Java 16 fails on unsupported methdod

我有一个基于 org.springframework.boot:spring-boot-starter-parent 版本 2.5.4-SNAPSHOT 和一些派生依赖项构建的简单应用程序:

我使用 org.springframework.experimental:spring-native 版本 0.10.3 启用 Spring 本机并使用以下插件构建:

<properties>
    <java.version>16</java.version>
</properties>
<!-- native-docker profile -->
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <image>
            <builder>paketobuildpacks/builder:tiny</builder>
            <env>
                <BP_BOOT_NATIVE_IMAGE>1</BP_BOOT_NATIVE_IMAGE>
            </env>
        </image>
        <fork>false</fork>
        <jvmArguments>--enable-preview</jvmArguments>
    </configuration>
</plugin>

我使用./mvnw.cmd spring-boot:build-image -Pnative-docker -DskipTests构建镜像,我放心Java 16被正确引导,然后镜像存在(为什么它是41岁,我不知道)。

[INFO]     [creator]     Paketo GraalVM Buildpack 6.4.2
[INFO]     [creator]       https://github.com/paketo-buildpacks/graalvm
[INFO]     [creator]       Build Configuration:
[INFO]     [creator]         $BP_JVM_VERSION            16.*           the Java version
$ docker images
REPOSITORY                  TAG              IMAGE ID       CREATED        SIZE
...
myapplication               0.0.1-SNAPSHOT   9bdb55e635ab   41 years ago   128MB

使用创建图像后,我使用 docker-compose up 启动数据库,然后启动应用程序(这是因为我之前通常使用 Dockerfile 构建图像并一起启动)和引发以下异常并且 Spring 启动应用程序将无法启动:

myapplication | Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'partyRepository' defined in com.myapplication.repository.MyFirstRepository defined in @EnableR2dbcRepositories declared on R2dbcRepositoriesAutoConfigureRegistrar.EnableR2dbcRepositoriesConfiguration: Invocation of init method failed; nested exception is com.oracle.svm.core.jdk.UnsupportedFeatureError: Unsupported method java.lang.Class.isSealed() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
myapplication |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=18=](AbstractBeanFactory.java:335) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[na:na]
myapplication |     at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1380) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[na:na]
myapplication |     at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[na:na]
myapplication |     ... 19 common frames omitted
myapplication | Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Unsupported method java.lang.Class.isSealed() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class

我假设 R2DBC 以某种方式使用 Class#isSealed,它在 Java 中处于启用预览模式 16. 如何使其成为 运行?

对于这个问题,已报告一个错误 #3870 afterwards on the Oracle/Graal 项目可在 GraalVM 21.3 上重现。

问题正在等待解决。