【发布时间】:2021-04-17 12:02:01
【问题描述】:
我的 spring 应用程序使用 mongodb 进行持久化。应用程序使用用户名/密码连接到 mongodb。
为了找到 Spring Native 的好处,我在我的 Ubuntu 18 LTS 上创建了一个 docker 映像。当我使用 docker compose 运行应用程序映像和 mongodb 映像时,一切看起来都很好。当我调用插入 mongodb 的 rest api 时,应用程序会抛出错误
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)
操作系统:Ubuntu 18 LTS
Spring 原生: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,混合模式,共享'''
参考https://www.graalvm.org/reference-manual/native-image/BuildConfiguration/#configuration-file-format,我还创建了一个 META-INF/native-image.properties 文件,内容如下
NativeImageArgs = --enable-all-security-services
即使在重建映像后,问题仍然存在。
我该如何解决这个问题?关于可能的解决方案的任何建议。
【问题讨论】:
-
这里似乎有很多很好的材料。 graalvm.org/reference-manual/native-image/JCASecurityServices -- 该页面说 enable-all 已被弃用,fwiw,所以也许它不再起作用了。它还说“本机映像构建器从底层 JVM 捕获提供者列表及其偏好顺序。”。我猜“底层”是指构建原生图像的那个?
-
我想知道的是,如果您的应用程序以某种方式尝试引导容器中的默认可用 JVM(SunJCE 版本 11),这在本机映像构建时不可用,因此无法自动注册后一旦在容器上运行就无法使用。
-
@Atmas 的描述似乎有很深的含义。我使用的JVM是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,混合模式,共享
标签: spring mongodb spring-boot spring-native