Spring Native issue when connecting to mongodb

467 Views Asked by At

My spring application uses mongodb for persistence. The application connects to mongodb using username/password.

To find benefits of Spring Native, I have created a docker image on my Ubuntu 18 LTS. When I run the app image and mongodb image using docker compose, everything looks good. When I invoke rest api which inserts into mongodb, the app throws an error

com.oracle.svm.core.jdk.UnsupportedFeatureError: Trying to verify a provider that was not registered at build time: SunJCE version 11. 
All providers must be registered and verified in the Native Image builder. 
Only the SUN provider is registered and verified by default. 
All other built-in providers are processed when all security services are enabled 
using the --enable-all-security-services option. 
Third party providers must be configured in the Native Image builder VM. 
at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:87)
native-demo |   at javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:384)
native-demo |   at javax.crypto.JceSecurity.canUseProvider(JceSecurity.java:231)
native-demo |   at javax.crypto.Mac.getInstance(Mac.java:186)
native-demo |   at com.mongodb.internal.connection.ScramShaAuthenticator$ScramShaSaslClient.hi(ScramShaAuthenticator.java:299)

OS: Ubuntu 18 LTS

Spring Native: 0.9.0

Spring Boot: 2.4.3

JDK: '''openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02) OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing '''

Referring to https://www.graalvm.org/reference-manual/native-image/BuildConfiguration/#configuration-file-format, I have also created a file META-INF/native-image.properties with following content NativeImageArgs = --enable-all-security-services

Even after rebuilding the image, the issue persist.

How do I fix this issue? Any suggestion on possible solution.

1

There are 1 best solutions below

1
On

Could you add a build argument on your spring-boot-maven-plugin?

                <configuration>
                    <image>
                        <builder>paketobuildpacks/builder:tiny</builder>
                        <env>
                            <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                            <BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
                                - H:IncludeResourceBundles=sun.security.util.Resources
                            </BP_NATIVE_IMAGE_BUILD_ARGUMENTS>
                        </env>
                    </image>
                </configuration>