Search code examples
springspring-bootjmsspring-annotations

Spring annotation value from configuration


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 (e.g. application.properties) instead of a hardcoded value?


Solution

  • 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