Skip to content

Commit 236b24a

Browse files
committed
Add controller predicate
Closes gh-1275
1 parent 8762570 commit 236b24a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

spring-graphql/src/main/java/org/springframework/graphql/data/method/annotation/support/AnnotatedControllerDetectionSupport.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ public abstract class AnnotatedControllerDetectionSupport<M> implements Applicat
102102
@Nullable
103103
private HandlerMethodArgumentResolverComposite argumentResolvers;
104104

105+
private Predicate<Class<?>> controllerPredicate =
106+
(beanType) -> AnnotatedElementUtils.hasAnnotation(beanType, Controller.class);
107+
105108
@Nullable
106109
private ApplicationContext applicationContext;
107110

@@ -202,6 +205,17 @@ protected HandlerMethodArgumentResolverComposite getArgumentResolvers() {
202205
return this.argumentResolvers;
203206
}
204207

208+
/**
209+
* Configure a predicate to determine if a given class should be introspected
210+
* for annotated controller methods.
211+
* <p>The default predicate looks for a type-level {@link Controller} annotation.
212+
* @param controllerPredicate the predicate to use
213+
* @since 1.4.3
214+
*/
215+
public void setControllerPredicate(Predicate<Class<?>> controllerPredicate) {
216+
this.controllerPredicate = controllerPredicate;
217+
}
218+
205219
@Override
206220
public void setApplicationContext(ApplicationContext applicationContext) {
207221
this.applicationContext = applicationContext;
@@ -251,7 +265,7 @@ protected Set<M> detectHandlerMethods() {
251265
this.logger.trace("Could not resolve type for bean '" + beanName + "'", ex);
252266
}
253267
}
254-
if (beanType == null || !AnnotatedElementUtils.hasAnnotation(beanType, Controller.class)) {
268+
if (beanType == null || !this.controllerPredicate.test(beanType)) {
255269
continue;
256270
}
257271
Class<?> beanClass = context.getType(beanName);

0 commit comments

Comments
 (0)