Skip to content

Commit be0931f

Browse files
committed
Added meta-annotation support to RetryableTopic
1 parent 86f6448 commit be0931f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
* @see org.springframework.kafka.retrytopic.RetryTopicConfigurer
4343
*/
44-
@Target({ ElementType.METHOD })
44+
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
4545
@Retention(RetentionPolicy.RUNTIME)
4646
@Documented
4747
public @interface RetryableTopic {

spring-kafka/src/test/java/org/springframework/kafka/retrytopic/RetryTopicConfigurationProviderTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import static org.mockito.Mockito.mock;
2626
import static org.mockito.Mockito.times;
2727

28+
import java.lang.annotation.ElementType;
29+
import java.lang.annotation.Retention;
30+
import java.lang.annotation.RetentionPolicy;
31+
import java.lang.annotation.Target;
2832
import java.lang.reflect.Method;
2933
import java.util.Collections;
3034

@@ -61,6 +65,8 @@ class RetryTopicConfigurationProviderTests {
6165

6266
private final Method nonAnnotatedMethod = getAnnotatedMethod("nonAnnotatedMethod");
6367

68+
private final Method metaAnnotatedMethod = getAnnotatedMethod("metaAnnotatedMethod");
69+
6470
private Method getAnnotatedMethod(String methodName) {
6571
try {
6672
return this.getClass().getDeclaredMethod(methodName);
@@ -136,6 +142,20 @@ void shouldFindNone() {
136142

137143
}
138144

145+
@Test
146+
void shouldProvideFromMetaAnnotation() {
147+
148+
// setup
149+
willReturn(kafkaOperations).given(beanFactory).getBean("retryTopicDefaultKafkaTemplate", KafkaOperations.class);
150+
151+
// given
152+
RetryTopicConfigurationProvider provider = new RetryTopicConfigurationProvider(beanFactory);
153+
RetryTopicConfiguration configuration = provider.findRetryConfigurationFor(topics, metaAnnotatedMethod, bean);
154+
155+
// then
156+
then(this.beanFactory).should(times(0)).getBeansOfType(RetryTopicConfiguration.class);
157+
158+
}
139159

140160
@Test
141161
void shouldNotConfigureIfBeanFactoryNull() {
@@ -157,4 +177,14 @@ public void annotatedMethod() {
157177
public void nonAnnotatedMethod() {
158178
// NoOps
159179
}
180+
181+
@Target({ElementType.METHOD})
182+
@Retention(RetentionPolicy.RUNTIME)
183+
@RetryableTopic
184+
static @interface MetaAnnotatedRetryableTopic { }
185+
186+
@MetaAnnotatedRetryableTopic
187+
public void metaAnnotatedMethod() {
188+
// NoOps
189+
}
160190
}

0 commit comments

Comments
 (0)