【问题标题】:Spring annotation value from configuration来自配置的 Spring 注释值
【发布时间】:2023-03-04 07:31:08
【问题描述】:

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

@Component
public class Consumer {

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

}

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

【问题讨论】:

    标签: spring spring-boot jms spring-annotations


    【解决方案1】:
    import org.springframework.beans.factory.annotation.Value;
    
    @JmsListener(destination = @Value("${jmx.image.index.queue}")
    public void receiveQueue(IndexRequest indexRequest) {
        ...
    }
    

    在你的属性文件中

    jmx.image.index.queue=image.index.queue
    

    【讨论】:

    • 类型不匹配:无法从值转换为字符串
    • 以下建设工程:@JmsListener(destination = "${jmx.image.index.queue}")
    猜你喜欢
    • 2018-10-25
    • 2012-03-23
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2010-09-23
    • 2010-09-23
    • 1970-01-01
    • 2021-11-21
    相关资源
    最近更新 更多