使用参数编写自定义 spring 注释?
Compose a custom spring annotation with a parameter?
这个注解可以转吗
@RabbitListener(
bindings = [QueueBinding(
key = [Amqp.FOLEY_NEW],
value = Queue(Amqp.FOLEY_NEW),
exchange = Exchange(name = "amq.topic", type = ExchangeTypes.TOPIC )
)]
)
添加到仅将队列名称作为参数的自定义注释中?
尝试一下,但我看不出可以参考 Listener.value
@Target(AnnotationTarget.FUNCTION)
@Retention
@RabbitListener(
bindings = [QueueBinding(
key = [Amqp.FOLEY_NEW],
value = Queue(Amqp.FOLEY_NEW),
exchange = Exchange(name = "amq.topic", type = ExchangeTypes.TOPIC )
)]
)
annotation class Listener( val value: String )
它不会起作用,因为自定义注释必须以某种方式引用元注释。 @RabbitListener
没有 value()
属性。尽管您可以尝试使用 @AliasFor
。有关详细信息,请参阅其 JavaDocs。
不过我不确定你的目标。您用一些 bindings
声明了一个 @RabbitListener
,其结果将在目标侦听器容器中使用。任何额外的队列(例如通过 queues()
)也将在容器中使用,即使您将能够使用 @AliasFor
实现设计。是你期待的吗?
这个注解可以转吗
@RabbitListener(
bindings = [QueueBinding(
key = [Amqp.FOLEY_NEW],
value = Queue(Amqp.FOLEY_NEW),
exchange = Exchange(name = "amq.topic", type = ExchangeTypes.TOPIC )
)]
)
添加到仅将队列名称作为参数的自定义注释中?
尝试一下,但我看不出可以参考 Listener.value
@Target(AnnotationTarget.FUNCTION)
@Retention
@RabbitListener(
bindings = [QueueBinding(
key = [Amqp.FOLEY_NEW],
value = Queue(Amqp.FOLEY_NEW),
exchange = Exchange(name = "amq.topic", type = ExchangeTypes.TOPIC )
)]
)
annotation class Listener( val value: String )
它不会起作用,因为自定义注释必须以某种方式引用元注释。 @RabbitListener
没有 value()
属性。尽管您可以尝试使用 @AliasFor
。有关详细信息,请参阅其 JavaDocs。
不过我不确定你的目标。您用一些 bindings
声明了一个 @RabbitListener
,其结果将在目标侦听器容器中使用。任何额外的队列(例如通过 queues()
)也将在容器中使用,即使您将能够使用 @AliasFor
实现设计。是你期待的吗?