Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 3392357

Browse files
committed
Fix webflux-kotlin sample and add KotlinRuntimeHints
1 parent 75c951e commit 3392357

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.springframework.aot.thirdpartyhints;
2+
3+
import org.springframework.aot.hint.MemberCategory;
4+
import org.springframework.aot.hint.ReflectionHints;
5+
import org.springframework.aot.hint.RuntimeHints;
6+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
7+
import org.springframework.aot.hint.TypeReference;
8+
import org.springframework.core.KotlinDetector;
9+
10+
/**
11+
* @author Sebastien Deleuze
12+
*/
13+
// TODO: Contribute these hints to graalvm-reachability-metadata repository
14+
public class KotlinRuntimeHints implements RuntimeHintsRegistrar {
15+
16+
17+
@Override
18+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
19+
if (!KotlinDetector.isKotlinReflectPresent()) {
20+
return;
21+
}
22+
hints.resources()
23+
.registerPattern("META-INF/*.kotlin_module")
24+
.registerPattern("*.kotlin_builtins");
25+
26+
ReflectionHints reflectionHints = hints.reflection();
27+
28+
reflectionHints.registerType(TypeReference.of("kotlin.reflect.full.KClasses"),
29+
builder -> {});
30+
reflectionHints.registerType(TypeReference.of("kotlin.Metadata"),
31+
builder ->builder.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
32+
reflectionHints.registerType(TypeReference.of("kotlin.reflect.jvm.internal.ReflectionFactoryImpl"),
33+
builder -> builder.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS));
34+
reflectionHints.registerType(TypeReference.of("kotlin.reflect.jvm.internal.impl.resolve.scopes.DescriptorKindFilter"),
35+
builder -> builder.withMembers(MemberCategory.DECLARED_FIELDS));
36+
}
37+
}

samples/webflux-kotlin/src/main/kotlin/com/example/webflux/WebfluxApplication.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.example.webflux
22

3+
import org.springframework.aot.thirdpartyhints.KotlinRuntimeHints
34
import org.springframework.aot.thirdpartyhints.NettyRuntimeHints
45
import org.springframework.boot.autoconfigure.SpringBootApplication
56
import org.springframework.boot.runApplication
67
import org.springframework.context.annotation.ImportRuntimeHints
78

89
@SpringBootApplication
9-
@ImportRuntimeHints(NettyRuntimeHints::class)
10+
@ImportRuntimeHints(NettyRuntimeHints::class, KotlinRuntimeHints::class)
1011
class WebfluxApplication
1112

1213
fun main(args: Array<String>) {

0 commit comments

Comments
 (0)