Spring annotation value from configuration

∥☆過路亽.° 提交于 2020-01-02 09:43:12

问题


In my Spring Boot application I have configured following JMS Listener:

@Component
public class Consumer {

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

}

How to supply destination name "image.index.queue" from configuration(application.properties) instead of hard-coded value ?


回答1:


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

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

And in your properties file

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


来源:https://stackoverflow.com/questions/38125348/spring-annotation-value-from-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!