[英]Using Spring Boot, how can I inject a JMS destination in @JmsListener annotation?
Using Spring Boot, how can I inject my JMS topic from a config property?使用 Spring Boot,如何从配置属性中注入我的 JMS 主题? I want to define the topic/queue name in application.properties
to be injected at runtime.我想在application.properties
中定义要在运行时注入的主题/队列名称。
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;
@Service
public class DispatcherService {
@Autowired ConfigProperties cp;
private final String dest = "my-topic";
private final String dest2 = cp.getTopic();
// WORKS
@JmsListener(destination = "my-topic")
public void receive1(String message) {
...
}
// WORKS
@JmsListener(destination = dest)
public void receive2(String message) {
...
}
// DOES NOT WORK - "Attribute must be constant"
@JmsListener(destination = dest2)
public void receive3(String message) {
...
}
// DOES NOT WORK - can I inject this here, somehow?
@JmsListener(destination = @Value("${topic}"))
public void receive4(String message) {
...
}
}
Try this:尝试这个:
@JmsListener(destination = "${my-topic}")
@JmsListener(destination = "\${config.property.key}")
, This should take the topic/queue name from configs. @JmsListener(destination = "\${config.property.key}")
,这应该从配置中获取主题/队列名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.