【发布时间】:2018-08-28 08:10:34
【问题描述】:
我希望能够从 application.properties 设置@JMSlistener 目标
我的代码是这样的
@Service
public class ListenerService {
private Logger log = Logger.getLogger(ListenerService.class);
@Autowired
QueueProperties queueProperties;
public ListenerService(QueueProperties queueProperties) {
this.queueProperties = queueProperties;
}
@JmsListener(destination = queueProperties.getQueueName() )
public void listenQueue(String requestJSON) throws JMSException {
log.info("Received " + requestJSON);
}
}
但是在构建时我得到了
Error:(25, 60) java: element value must be a constant expression
【问题讨论】:
-
你可以在目的地尝试#listenerService.queueProperties.getQueueName()
-
我得到这个错误:(25, 47) java: non-static variable queueProperties cannot be referenced from a static context
-
你用大括号试过了吗,所以大括号中的“#{}”指定了我上面提到的内容。
标签: java spring-boot jms spring-jms jmstemplate