Home > front end >  Spring @AliasFor with property for nested annotation
Spring @AliasFor with property for nested annotation

Time:11-18

Is it possible to have @AliasFor annotation pass the argument to nested annotation? Something like passing value of name() to nested @Queue annotation inside @RabbitListener? I basically wanted to specify multiple queues with same binding parameters to same exchange, and only vary queue name.

enter image description here

CodePudding user response:

I don't think you can do that for nested annotations. You probably need to think about having a custom @Queue annotation extension and then used it inside your @SomeListener. But the problem is that @Queue annotation cannot be extended. It has that @Target({}), so it is not possible at the moment.

If you really wish to have such a customization, consider to fix Spring AMQP on the matter via @Target(ANNOTATION_TYPE) and add some tests to demonstrate the feature and contribute it back to the framework.

Unfortunately I don't see the other way to support your request, unless you would go the to declare Queue beans and use just their names in that your custom annotation:

@Retention(RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD })
@RabbitListener
public @interface MyListener {
    
    @AliasFor(annotation = RabbitListener.class, attribute = "queues")
    String[] queues() default {};
    
}
  • Related