Skip to content

Commit 11bc4ec

Browse files
committed
GH-2384 - Explicitly register proxy metadata for LastInvocationAware for native images.
1 parent 8cf1d68 commit 11bc4ec

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

src/main/java/org/springframework/hateoas/aot/HateoasTypesRuntimeHints.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515
*/
1616
package org.springframework.hateoas.aot;
1717

18+
import java.util.Map;
19+
1820
import org.jspecify.annotations.Nullable;
21+
import org.springframework.aop.SpringProxy;
22+
import org.springframework.aop.framework.Advised;
1923
import org.springframework.aot.hint.RuntimeHints;
2024
import org.springframework.aot.hint.RuntimeHintsRegistrar;
25+
import org.springframework.core.DecoratingProxy;
2126
import org.springframework.hateoas.RepresentationModel;
27+
import org.springframework.hateoas.server.core.LastInvocationAware;
2228

2329
/**
2430
* Registers reflection metadata for {@link RepresentationModel} types.
@@ -38,5 +44,10 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
3844
var reflection = hints.reflection();
3945

4046
AotUtils.registerTypesForReflection(packageName, reflection);
47+
48+
// Proxy metadata for DummyInvocationUtils
49+
hints.proxies()
50+
.registerJdkProxy(LastInvocationAware.class, Map.class, SpringProxy.class, Advised.class,
51+
DecoratingProxy.class);
4152
}
4253
}

src/test/java/org/springframework/hateoas/aot/HateoasTypesRuntimeHintsUnitTests.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,23 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20+
import java.util.List;
21+
import java.util.Map;
22+
2023
import org.junit.jupiter.api.Test;
24+
import org.springframework.aop.SpringProxy;
25+
import org.springframework.aop.framework.Advised;
26+
import org.springframework.aot.hint.JdkProxyHint;
2127
import org.springframework.aot.hint.RuntimeHints;
2228
import org.springframework.aot.hint.TypeHint;
2329
import org.springframework.aot.hint.TypeReference;
30+
import org.springframework.core.DecoratingProxy;
2431
import org.springframework.hateoas.Link;
2532
import org.springframework.hateoas.Links;
33+
import org.springframework.hateoas.server.core.LastInvocationAware;
2634

2735
/**
28-
* Unit tests for {@link RepresentationModelRuntimeHints}.
36+
* Unit tests for {@link HateoasTypesRuntimeHints}.
2937
*
3038
* @author Oliver Drotbohm
3139
*/
@@ -34,16 +42,31 @@ class HateoasTypesRuntimeHintsUnitTests {
3442
@Test // GH-1981
3543
void registersHintsForHateoasTypes() {
3644

37-
var registrar = new HateoasTypesRuntimeHints();
38-
var hints = new RuntimeHints();
39-
40-
registrar.registerHints(hints, getClass().getClassLoader());
41-
42-
assertThat(hints.reflection().typeHints())
45+
assertThat(createHints().reflection().typeHints())
4346
.extracting(TypeHint::getType)
4447
.extracting(TypeReference::getSimpleName)
4548
.contains("MapSuppressingUnwrappingSerializer", //
4649
Link.class.getSimpleName(), //
4750
Links.class.getSimpleName());
4851
}
52+
53+
@Test // GH-2384
54+
void registersProxyHintsForLastInvocationAware() {
55+
56+
assertThat(createHints().proxies().jdkProxyHints())
57+
.extracting(JdkProxyHint::getProxiedInterfaces)
58+
.contains(List.of(TypeReference.of(LastInvocationAware.class), TypeReference.of(Map.class),
59+
TypeReference.of(SpringProxy.class), TypeReference.of(Advised.class),
60+
TypeReference.of(DecoratingProxy.class)));
61+
}
62+
63+
private static RuntimeHints createHints() {
64+
65+
var registrar = new HateoasTypesRuntimeHints();
66+
var hints = new RuntimeHints();
67+
68+
registrar.registerHints(hints, HateoasTypesRuntimeHintsUnitTests.class.getClassLoader());
69+
70+
return hints;
71+
}
4972
}

0 commit comments

Comments
 (0)