Skip to content

Commit 827e308

Browse files
Addressing PR review
Signed-off-by: chickenchickenlove <[email protected]>
1 parent c3f44f1 commit 827e308

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,18 @@ public Object postProcessAfterInitialization(final Object bean, final String bea
407407
this.logger.debug(() -> annotatedMethods.size() + " @KafkaListener methods processed on bean '"
408408
+ beanName + "': " + annotatedMethods);
409409
}
410-
Set<Method> methodsWithHandler = MethodIntrospector.selectMethods(targetClass,
411-
(ReflectionUtils.MethodFilter) method ->
412-
AnnotationUtils.findAnnotation(method, KafkaHandler.class) != null);
413-
boolean hasMethodLevelKafkaHandlerAnnotation = !methodsWithHandler.isEmpty();
414410
if (hasClassLevelListeners) {
411+
Set<Method> methodsWithHandler = MethodIntrospector.selectMethods(targetClass,
412+
(ReflectionUtils.MethodFilter) method ->
413+
AnnotationUtils.findAnnotation(method, KafkaHandler.class) != null);
414+
415+
if (methodsWithHandler.isEmpty()) {
416+
throw new IllegalStateException("No Kafka listener methods in bean: " + bean);
417+
}
418+
415419
List<Method> multiMethods = new ArrayList<>(methodsWithHandler);
416420
processMultiMethodListeners(classLevelListeners, multiMethods, targetClass, bean, beanName);
417421
}
418-
419-
if (!hasMethodLevelListeners && hasClassLevelListeners &&
420-
!hasMethodLevelKafkaHandlerAnnotation) {
421-
throw new IllegalStateException("No Kafka listener methods in bean: " + bean);
422-
}
423422
}
424423
}
425424
return bean;

spring-kafka/src/test/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessorTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void ctx_should_be_fail_to_register_bean_when_no_listener_methods_exist() {
4141

4242
assertThatExceptionOfType(BeanCreationException.class)
4343
.isThrownBy(ctx::refresh)
44-
.withMessageContaining("No kafka listener methods found on bean type.")
44+
.withRootCauseInstanceOf(IllegalStateException.class)
45+
.withMessageContaining("No Kafka listener methods in bean:")
4546
.withMessageContaining("NoHandlerMethodListener");
4647

4748
}

0 commit comments

Comments
 (0)