Java 16上Spring R2DBC应用程序的Spring Boot Docker本机映像在不受支持的methdod



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

  • org.springframework.boot:spring-boot-starter-data-r2dbc
  • org.springframework.boot:spring-boot-starter-webflux
  • org.springframework.boot:spring-boot-starter-actuator
  • io.r2dbc:r2dbc-postgresql

我使用org.springframework.experimental:spring-native版本0.10.3来启用Spring Native,并使用以下插件进行构建:

<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 Boot应用程序不会启动:

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$0(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中处于启用预览模式。如何使其运行?

对于这个问题,在GraalVM 21.3上可复制的Oracle/Gral项目上报告了一个错误#3870。

这个问题正在等待解决。

最新更新