配置中的Spring注释值

ale*_*oid 2 spring jms spring-annotations spring-boot

在我的Spring Boot应用程序中,我配置了以下JMS侦听器:

@Component
public class Consumer {

    @JmsListener(destination = "image.index.queue")
    public void receiveQueue(IndexRequest indexRequest) {
        ...
    }

}
Run Code Online (Sandbox Code Playgroud)

如何从配置(application.properties)中提供目标名称“ image.index.queue”,而不是硬编码值?

tec*_*abu 5

import org.springframework.beans.factory.annotation.Value;

@JmsListener(destination = @Value("${jmx.image.index.queue}")
public void receiveQueue(IndexRequest indexRequest) {
    ...
}
Run Code Online (Sandbox Code Playgroud)

并在您的属性文件中

jmx.image.index.queue=image.index.queue
Run Code Online (Sandbox Code Playgroud)

  • 类型不匹配:无法从“值”转换为“字符串” (3认同)
  • 以下建设工程:@JmsListener(destination = "${jmx.image.index.queue}") (2认同)