GraalVM 和 Kotlin 内联值类?

问题描述 投票:0回答:1

我想在本机图像中使用值类:

@JvmInline
value class MyValueClass(val id: UUID)

我将其标记为反思:

@Configuration(proxyBeanMethods = false)
@RegisterReflectionForBinding(MyValueClass::class, ...)
class BeanConfiguration {

但是,当运行图像时我得到:

org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method public final java.util.UUID com.example.MyValueClass.unbox-impl() without it being registered for runtime reflection. Add it to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
    at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils.forQueriedOnlyExecutable(MissingReflectionRegistrationUtils.java:97) ~[na:na]

如何将内联值类与 GraalVM 一起使用?

java kotlin reflection graalvm graalvm-native-image
1个回答
0
投票

我通过以下提示让它在 Spring Boot 3.3 中工作(我的值类是

TimestampMicros
)。 这使得所有成员都可用于反射,包括 kotlin 编译器生成的成员。也许可以微调包含的会员类别,但我没有尝试过:

@SpringBootApplication
@ImportRuntimeHints(PollingApplication.Hints::class)
class PollingApplication {
    class Hints : RuntimeHintsRegistrar {
        override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {
            hints.reflection().registerTypeIfPresent(classLoader, TimestampMicros::class.java.name) {
                it.withMembers(*MemberCategory.entries.toTypedArray())
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.