Skip to content

Commit 62f82f7

Browse files
Revert to a52facc
Signed-off-by: chickenchickenlove <[email protected]>
1 parent 19f9371 commit 62f82f7

File tree

5 files changed

+4
-187
lines changed

5 files changed

+4
-187
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/class-level-kafkalistener.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[[class-level-kafkalistener]]
22
= `@KafkaListener` on a Class
33

4-
When you use `@KafkaListener` at the class-level, if there is only one public method, you do not need to specify `@KafkaHandler`.
5-
However, if there are multiple public methods, you must specify `@KafkaHandler` at the method level.
4+
When you use `@KafkaListener` at the class-level, you must specify `@KafkaHandler` at the method level.
65
When messages are delivered, the converted message payload type is used to determine which method to call.
76
The following example shows how to do so:
87

@@ -59,3 +58,4 @@ void listen(Object in, @Header(KafkaHeaders.RECORD_METADATA) ConsumerRecordMetad
5958
...
6059
}
6160
----
61+

spring-kafka-docs/src/main/antora/modules/ROOT/pages/whats-new.adoc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,3 @@ Several deprecated items have been removed:
7070

7171
Spring for Apache Kafka 4.0 supports Kafka 4.0’s new consumer rebalance protocol - https://cwiki.apache.org/confluence/display/KAFKA/KIP-848%3A+The+Next+Generation+of+the+Consumer+Rebalance+Protocol[KIP-848].
7272
For details, see xref:kafka/receiving-messages/rebalance-listeners.adoc#new-rebalalcne-protocol[New Consumer Rebalace Protocol docs].
73-
74-
[[x40-single-public-method-listener]]
75-
=== Single Public Method Listener Simplification
76-
77-
Spring for Apache Kafka 4.0 simplifies the use of class-level `@KafkaListener` annotations.
78-
Previously, when `@KafkaListener` was declared at the class level, each public method intended to handle messages had to be annotated explicitly with `@KafkaHandler`.
79-
Now, if there is exactly one public method in the class, it will be automatically recognized as the listener method even without the `@KafkaHandler` annotation. For details, see xref:kafka/receiving-messages/class-level-kafkalistener.adoc#class-level-kafkalistener[Class Level Kafka Listener].

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.StringReader;
2121
import java.lang.reflect.AnnotatedElement;
2222
import java.lang.reflect.Method;
23-
import java.lang.reflect.Modifier;
2423
import java.nio.ByteBuffer;
2524
import java.nio.charset.Charset;
2625
import java.nio.charset.StandardCharsets;
@@ -412,20 +411,8 @@ public Object postProcessAfterInitialization(final Object bean, final String bea
412411
Set<Method> methodsWithHandler = MethodIntrospector.selectMethods(targetClass,
413412
(ReflectionUtils.MethodFilter) method ->
414413
AnnotationUtils.findAnnotation(method, KafkaHandler.class) != null);
415-
Set<Method> publicMethods = MethodIntrospector.selectMethods(targetClass,
416-
(ReflectionUtils.MethodFilter) method ->
417-
Modifier.isPublic(method.getModifiers()));
418-
419-
if (methodsWithHandler.isEmpty() && publicMethods.size() == 1 && !hasMethodLevelListeners) {
420-
Method method = publicMethods.iterator().next();
421-
for (KafkaListener classLevelListener : classLevelListeners) {
422-
processKafkaListener(classLevelListener, method, bean, beanName);
423-
}
424-
}
425-
else {
426-
List<Method> multiMethods = new ArrayList<>(methodsWithHandler);
427-
processMultiMethodListeners(classLevelListeners, multiMethods, targetClass, bean, beanName);
428-
}
414+
List<Method> multiMethods = new ArrayList<>(methodsWithHandler);
415+
processMultiMethodListeners(classLevelListeners, multiMethods, targetClass, bean, beanName);
429416
}
430417
}
431418
}

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.core.Ordered;
3737
import org.springframework.core.annotation.AliasFor;
3838
import org.springframework.kafka.annotation.AliasPropertiesTests.Config.ClassAndMethodLevelListener;
39-
import org.springframework.kafka.annotation.AliasPropertiesTests.Config.ClassLevelListenerWithPublicMethodWithoutHandlerAnnotation;
4039
import org.springframework.kafka.annotation.KafkaListenerAnnotationBeanPostProcessor.AnnotationEnhancer;
4140
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
4241
import org.springframework.kafka.config.KafkaListenerConfigUtils;
@@ -59,7 +58,6 @@
5958
* @author Gary Russell
6059
* @author Artem Bilan
6160
* @author Soby Chacko
62-
* @author Sanghyeok An
6361
*
6462
* @since 2.2
6563
*
@@ -83,16 +81,12 @@ public class AliasPropertiesTests {
8381
@Autowired
8482
private ClassAndMethodLevelListener repeatable;
8583

86-
@Autowired
87-
private ClassLevelListenerWithPublicMethodWithoutHandlerAnnotation withPublicMethod;
88-
8984
@Test
9085
public void testAliasFor() throws Exception {
9186
this.template.send("alias.tests", "foo");
9287
assertThat(this.config.latch.await(10, TimeUnit.SECONDS)).isTrue();
9388
assertThat(this.classLevel.latch.await(10, TimeUnit.SECONDS)).isTrue();
9489
assertThat(this.repeatable.latch.await(10, TimeUnit.SECONDS)).isTrue();
95-
assertThat(this.withPublicMethod.latch.await(10, TimeUnit.SECONDS)).isTrue();
9690
assertThat(this.config.kafkaListenerEndpointRegistry()).isSameAs(this.kafkaListenerEndpointRegistry);
9791
assertThat(this.kafkaListenerEndpointRegistry.getListenerContainer("onMethodInConfigClass").getGroupId())
9892
.isEqualTo("onMethodInConfigClass.Config.listen1");
@@ -108,8 +102,6 @@ public void testAliasFor() throws Exception {
108102
.isEqualTo("onMethodRepeatable2.RepeatableClassAndMethodLevelListener.listen1");
109103
assertThat(this.kafkaListenerEndpointRegistry.getListenerContainer("onClassRepeatable2").getGroupId())
110104
.isEqualTo("onClassRepeatable2.RepeatableClassAndMethodLevelListener");
111-
assertThat(this.kafkaListenerEndpointRegistry.getListenerContainer("onSinglePublicMethod").getGroupId())
112-
.isEqualTo("onSinglePublicMethod.ClassLevelListenerWithPublicMethodWithoutHandlerAnnotation");
113105
assertThat(Config.orderedCalledFirst.get()).isTrue();
114106
}
115107

@@ -228,18 +220,6 @@ public void listen1(String in) {
228220

229221
}
230222

231-
@Component
232-
@MyListener(id = "onSinglePublicMethod", value = "alias.tests")
233-
public static class ClassLevelListenerWithPublicMethodWithoutHandlerAnnotation {
234-
235-
private final CountDownLatch latch = new CountDownLatch(1);
236-
237-
public void listen(String in) {
238-
this.latch.countDown();
239-
}
240-
241-
}
242-
243223
public static class OrderedEnhancer implements AnnotationEnhancer, Ordered {
244224

245225
private final AtomicBoolean orderedCalledFirst;

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

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)