Skip to content
Advertisement

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-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:

<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).

[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:

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?

Advertisement

Answer

For this problem, there has been reported a bug #3870 afterwards on the Oracle/Graal project reproducible on GraalVM 21.3.

The issue is waiting for its resolution.

Advertisement