【发布时间】:2020-07-22 08:54:57
【问题描述】:
我正在尝试在我的项目中使用 SimpMessagingTemplate 类通过 websocket 发送一些数据。
问题是我总是出错,这里是完整的错误:
Error creating bean with name 'webSocketUserNotificationManagerImpl' defined in URL [...]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.messaging.simp.SimpMessagingTemplate' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
这里是webSocketuserNotificationManagerImpl 服务:
@Service
public class WebSocketUserNotificationManagerImpl implements UserNotificationManager {
/**
* Template to use to send back a message to the user via Web-socket.
*/
private SimpMessagingTemplate template;
public WebSocketUserNotificationManagerImpl(SimpMessagingTemplate template) {
this.template = template;
}
private ObjectMapper jsonMapper = new ObjectMapper();
@Override
public void sendMessageToUser(String jobName, String eventType, Result result) {
....
}
public void sendDeleteMessageToUser(DeleteRequestsSocketMessage message, Principal principal) {
this.template.convertAndSendToUser(principal.getName().toLowerCase(),
"/status/delete", message);
}
}
我的 pom 中有这个依赖项:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-messaging</artifactId>
</dependency>
怎么了,为什么SimpMessagingTemplate bean 不存在?
【问题讨论】: