3333import org .springframework .context .annotation .Bean ;
3434import org .springframework .context .annotation .Configuration ;
3535import org .springframework .core .annotation .AliasFor ;
36+ import org .springframework .kafka .annotation .AliasPropertiesTests .Config .ClassLevelListener ;
3637import org .springframework .kafka .config .ConcurrentKafkaListenerContainerFactory ;
3738import org .springframework .kafka .config .KafkaListenerConfigUtils ;
3839import org .springframework .kafka .config .KafkaListenerContainerFactory ;
4344import org .springframework .kafka .core .ProducerFactory ;
4445import org .springframework .kafka .test .EmbeddedKafkaBroker ;
4546import org .springframework .kafka .test .utils .KafkaTestUtils ;
47+ import org .springframework .stereotype .Component ;
4648import org .springframework .test .annotation .DirtiesContext ;
4749import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
4850
@@ -66,11 +68,15 @@ public class AliasPropertiesTests {
6668 @ Autowired
6769 private KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry ;
6870
71+ @ Autowired
72+ private ClassLevelListener classLevel ;
73+
6974 @ Test
7075 public void testAliasFor () throws Exception {
7176 this .template .send ("alias.tests" , "foo" );
7277 assertThat (this .config .latch .await (10 , TimeUnit .SECONDS )).isTrue ();
7378 assertThat (this .config .kafkaListenerEndpointRegistry ()).isSameAs (this .kafkaListenerEndpointRegistry );
79+ assertThat (this .classLevel .latch .await (10 , TimeUnit .SECONDS )).isTrue ();
7480 }
7581
7682 @ Configuration
@@ -125,18 +131,34 @@ public Map<String, Object> producerConfigs() {
125131 return KafkaTestUtils .producerProps (embeddedKafka ());
126132 }
127133
128- @ MyListener ("alias.tests" )
134+ @ MyListener (id = "onMethod" , value = "alias.tests" )
129135 public void listen1 (String in ) {
130- latch .countDown ();
136+ this .latch .countDown ();
137+ }
138+
139+ @ Component
140+ @ MyListener (id = "onClass" , value = "alias.tests" )
141+ public static class ClassLevelListener {
142+
143+ private final CountDownLatch latch = new CountDownLatch (1 );
144+
145+ @ KafkaHandler
146+ void listen (String in ) {
147+ this .latch .countDown ();
148+ }
149+
131150 }
132151
133152 }
134153
135- @ Target (ElementType .METHOD )
154+ @ Target ({ ElementType .METHOD , ElementType . TYPE } )
136155 @ Retention (RetentionPolicy .RUNTIME )
137156 @ KafkaListener
138157 public @interface MyListener {
139158
159+ @ AliasFor (annotation = KafkaListener .class , attribute = "id" )
160+ String id () default "" ;
161+
140162 @ AliasFor (annotation = KafkaListener .class , attribute = "topics" )
141163 String [] value ();
142164
0 commit comments