简体   繁体   English

Java 16 上 Spring R2DBC 应用程序的 Spring Boot Docker Native 映像在不受支持的方法上失败

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

I have a simple application built on top of org.springframework.boot:spring-boot-starter-parent version 2.5.4-SNAPSHOT and some derived dependencies:我有一个简单的应用程序构建在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

I use org.springframework.experimental:spring-native version 0.10.3 to enable Spring Native and build using the following plugin:我使用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>

I build the image using ./mvnw.cmd spring-boot:build-image -Pnative-docker -DskipTests , I get assured Java 16 is bootstrapped correctly, and then the image exists (why it is 41 years old, I have no clue).我使用./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

After the image is created using, I use docker-compose up to start up the database and then the application (this works as I previously built an image normally using Dockerfile and started together) and the following exception is raised and the Spring Boot application won't start:使用创建映像后,我使用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

I assume R2DBC somehow uses Class#isSealed which is in the enable preview mode in Java 16. How to make it run?我假设 R2DBC 以某种方式使用了 Java 16 中处于启用预览模式的Class#isSealed 。如何让它运行?

For this problem, there has been reported a bug #3870 afterwards on the Oracle/Graal project reproducible on GraalVM 21.3.对于这个问题,后来在 GraalVM 21.3 上可重现的Oracle/Graal项目上报告了一个错误#3870

The issue is waiting for its resolution.问题正在等待解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM