下面是我下面的Spring Boot应用程序,我试图将消息发送到Queue,但它总是在jmsTemplate
上抛出NULL。根据Spring文档,jmsTemplate
应该自动配置,但它没有发生。这是我做错了什么吗?
服务等级
@Service
@EnableJms
public class CTCall {
@Autowired
private JmsTemplate jmsTemplate; //THIS ALWAYS Throw NULL
public String send() {
try {
System.out.println("jmsTemplate: " + jmsTemplate);
jmsTemplate.convertAndSend("MYQUEUE", "Hello World!");
return "OK";
} catch (Exception ex) {
ex.printStackTrace();
return "FAIL";
}
}
}
application.properties
ibm.mq.queueManager=MYMGR
ibm.mq.channel=MYQUUE
ibm.mq.connName=MYHOST(1414)
ibm.mq.user=
ibm.mq.password=
POM-
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>mq-jms-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
您必须将@EnableJms添加到@SpringBootApplication或@Configuration类