Browse Source

Add the necessary hints for use of Cglib proxies

This commit expands GeneratedClassHandler to allow invocation of
declared fields and methods. Generated proxies have a number of
internal fields and methods that are invoked via reflection.

See gh-28954
pull/28964/head
Stephane Nicoll 3 years ago
parent
commit
3086d90e7d
  1. 4
      spring-context/src/main/java/org/springframework/context/aot/GeneratedClassHandler.java
  2. 3
      spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java

4
spring-context/src/main/java/org/springframework/context/aot/GeneratedClassHandler.java

@ -39,7 +39,9 @@ import org.springframework.core.io.ByteArrayResource; @@ -39,7 +39,9 @@ import org.springframework.core.io.ByteArrayResource;
class GeneratedClassHandler implements BiConsumer<String, byte[]> {
private static final Consumer<Builder> asCglibProxy = hint ->
hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_DECLARED_METHODS,
MemberCategory.DECLARED_FIELDS);
private final RuntimeHints runtimeHints;

3
spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java

@ -54,7 +54,8 @@ class GeneratedClassHandlerTests { @@ -54,7 +54,8 @@ class GeneratedClassHandlerTests {
String className = "com.example.Test$$Proxy$$1";
this.handler.accept(className, TEST_CONTENT);
assertThat(RuntimeHintsPredicates.reflection().onType(TypeReference.of(className))
.withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS))
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS))
.accepts(this.generationContext.getRuntimeHints());
}

Loading…
Cancel
Save