有时控制台错误向我显示消息
Calling is not valid for a request with Async state
控制器
@GetMapping(value = "user/push", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter fetchNotify(@AuthenticationPrincipal CustomOAuth2User oAuth2User) {
try{
notificationService.addEmitter(UNIQUE_KEY, DATA_SET);
} catch(Exception e){
log.debug("Error : {}", e.getMessage());
return emitter;
}
notificationService.addEmitter 是“服务层”字段中添加ConcurrentMap
服务
@Transactional
@Scheduled(initialDelay = 2000, fixedDelay = 7000)
public void fetch(){
// blahblahblah
emitter.send(alertData, MediaType.APPLICATION_JSON_UTF8);
// blahblahblah
}
emitter.send()方法正在将数据从服务器发送到客户端。
当我尝试使用此代码时,会出错,但是过程进展顺利,向我展示了吗?