问题
I have the same problem mentioned in this unanswered question: Spring Cloud AWS SQS SendTo annotation with property placeholder
But, I'm asking it again more succinctly in hopes that it will be answered this time.
As mentioned in the question I had referred to, this issue: https://github.com/spring-cloud/spring-cloud-aws/issues/65 seems to indicated that the @SentTo
annotation should support property placeholders.
However, when it comes to the @SendTo
annotation, the Spring AMQP documentation only talks about SpEL (bean evaluation '#{...}' and runtime '!{...}'), but doesn't mention property placeholders.
When I tried using @SendTo("${my.reply.routing.key}")
or @SendTo("${my-exchange}/${my.reply.routing.key}")
, is being interpreted literally and isn't being properly interpolated.
Are there any workarounds for me to use property placeholder in this case?
回答1:
It only supports expressions; you can work around it, though; such as by using a bean reference:
@SpringBootApplication
public class So51620793Application {
public static void main(String[] args) {
SpringApplication.run(So51620793Application.class, args);
}
@RabbitListener(queues = "foo")
@SendTo("#{@sendTo}")
public String listen(Message in) {
System.out.println(in);
return new String(in.getBody()).toUpperCase();
}
@Bean
public String sendTo(@Value("${foo.bar}") String sendTo) {
return sendTo;
}
}
I am not familiar with the AWS code; each project rolls its own for this annotation.
来源:https://stackoverflow.com/questions/51620793/use-property-placeholder-with-spring-amqp-sendto-annotation