Introduce ReflectiveScan
This commit allows `@Reflective` to be used on arbitrary types, not only Spring beans. This makes the feature much more powerful as components can be tagged directly. Scanning happens during AOT processing (typically at build-time) when `@ReflectiveScan` is used. Types do not need to have a particular annotation, and types that can't be loaded are ignored. This commit also exposes the infrastructure that does the scanning so that custom code can do the scanning in an AOT contribution if they don't want to rely on the annotation. Closes gh-33132
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.aot.hint.annotation;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -24,6 +25,8 @@ import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import org.springframework.aot.hint.FieldHint;
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
@@ -50,6 +53,20 @@ class ReflectiveRuntimeHintsRegistrarTests {
|
||||
|
||||
private final RuntimeHints runtimeHints = new RuntimeHints();
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(classes = { SampleTypeAnnotatedBean.class, SampleFieldAnnotatedBean.class,
|
||||
SampleConstructorAnnotatedBean.class, SampleMethodAnnotatedBean.class, SampleInterface.class,
|
||||
SampleMethodMetaAnnotatedBeanWithAlias.class, SampleMethodAnnotatedBeanWithInterface.class })
|
||||
void isCandidateWithMatchingAnnotatedElement(Class<?> candidate) {
|
||||
assertThat(this.registrar.isCandidate(candidate)).isTrue();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(classes = { String.class, Closeable.class })
|
||||
void isCandidateWithNonMatchingAnnotatedElement(Class<?> candidate) {
|
||||
assertThat(this.registrar.isCandidate(candidate)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIgnoreNonAnnotatedType() {
|
||||
RuntimeHints mock = mock();
|
||||
|
||||
Reference in New Issue
Block a user