我按照本教程创建了简单的 JMS 相关应用程序,但我不断收到异常(下面粘贴了堆栈跟踪)
我尝试查看其他类似的线程,并且在许多地方看起来人们要求在界面中添加 @Repository 注释,但我的界面没有扩展任何存储库。
我的代码如下所示:
JmsClient.java
public interface JmsClient {
public void send(String msg);
public String receive();
}
JmsClientImpl.java
@Service
public class JmsClientImpl implements JmsClient{
@Autowired
JmsConsumer jmsConsumer;
@Autowired
JmsProducer jmsProducer;
@Override
public void send(String msg) {
jmsProducer.send(msg);
}
@Override
public String receive() {
return jmsConsumer.receive();
}
}
JmsConsumer.java
@Component
public class JmsConsumer {
@Autowired
JmsTemplate jmsTemplate;
@Value("${jms.queue.destination}")
String destinationQueue;
public String receive(){
return (String)jmsTemplate.receiveAndConvert(destinationQueue);
}
}
WebController.java
@RestController
public class WebController {
@Autowired
JmsClient jsmClient;
@RequestMapping(value="/produce")
public String produce(@RequestParam("msg")String msg){
jsmClient.send(msg);
return "Done";
}
@RequestMapping(value="/receive")
public String receive(){
return jsmClient.receive();
}
}
JmsProducer.java
@Component
public class JmsProducer {
@Autowired
JmsTemplate jmsTemplate;
@Value("${jms.queue.destination}")
String destinationQueue;
public void send(String msg){
jmsTemplate.convertAndSend(destinationQueue, msg);
}
}
开满天机
相关分类