Search implemented interfaces on superclass for @ServiceConnection
Refine original fix to also search interfaces on the superclass. Fixes gh-37671
This commit is contained in:
@@ -54,7 +54,10 @@ class ServiceConnectionContextCustomizerFactory implements ContextCustomizerFact
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void findSources(Class<?> clazz, List<ContainerConnectionSource<?>> sources) {
|
private void findSources(Class<?> clazz, List<ContainerConnectionSource<?>> sources) {
|
||||||
ReflectionUtils.doWithFields(clazz, (field) -> {
|
if (clazz == Object.class || clazz == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ReflectionUtils.doWithLocalFields(clazz, (field) -> {
|
||||||
MergedAnnotations annotations = MergedAnnotations.from(field);
|
MergedAnnotations annotations = MergedAnnotations.from(field);
|
||||||
annotations.stream(ServiceConnection.class)
|
annotations.stream(ServiceConnection.class)
|
||||||
.forEach((annotation) -> sources.add(createSource(field, annotation)));
|
.forEach((annotation) -> sources.add(createSource(field, annotation)));
|
||||||
@@ -65,6 +68,7 @@ class ServiceConnectionContextCustomizerFactory implements ContextCustomizerFact
|
|||||||
for (Class<?> implementedInterface : clazz.getInterfaces()) {
|
for (Class<?> implementedInterface : clazz.getInterfaces()) {
|
||||||
findSources(implementedInterface, sources);
|
findSources(implementedInterface, sources);
|
||||||
}
|
}
|
||||||
|
findSources(clazz.getSuperclass(), sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@@ -94,6 +94,14 @@ class ServiceConnectionContextCustomizerFactoryTests {
|
|||||||
assertThat(customizer.getSources()).hasSize(2);
|
assertThat(customizer.getSources()).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createContextCustomizerWhenInheritedImplementedInterfaceHasServiceConnectionsReturnsCustomizer() {
|
||||||
|
ServiceConnectionContextCustomizer customizer = (ServiceConnectionContextCustomizer) this.factory
|
||||||
|
.createContextCustomizer(ServiceConnectionsImplSubclass.class, null);
|
||||||
|
assertThat(customizer).isNotNull();
|
||||||
|
assertThat(customizer.getSources()).hasSize(2);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createContextCustomizerWhenClassHasNonStaticServiceConnectionFailsWithHelpfulException() {
|
void createContextCustomizerWhenClassHasNonStaticServiceConnectionFailsWithHelpfulException() {
|
||||||
assertThatIllegalStateException()
|
assertThatIllegalStateException()
|
||||||
@@ -186,6 +194,10 @@ class ServiceConnectionContextCustomizerFactoryTests {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class ServiceConnectionsImplSubclass extends ServiceConnectionsImpl {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static class NonStaticServiceConnection {
|
static class NonStaticServiceConnection {
|
||||||
|
|
||||||
@ServiceConnection
|
@ServiceConnection
|
||||||
|
|||||||
Reference in New Issue
Block a user