我有一个带有用户通知(例如Facebook,Twitter,Instagram通知)的Web应用程序。每当某个术语过期时,我都需要返回到前端通知,因此后端必须每次检查是否有任何术语即将过期或是否已经过期。这就是为什么我想创建一个请求,例如每5分钟返回一次请求。
我已经尝试过Spring @Schedule和WebSocket。
使用时间表:
@Scheduled(fixedDelay = 1000)
@GetMapping(value = "/notification/get", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> returnsNotification() throws InterruptedException {
Thread.sleep(4000);
List<Notification> notifications = seachNotifications();
return new ResponseEntity<>(notifications, HttpStatus.OK);
}
我的问题是,使用此代码,我的日程安排无法正常工作,因此前端必须每次都调用该请求。
使用websocket我还不知道如何使用它。
您是否已使用@EnableScheduling在spring应用程序中激活了@Scheduled?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句