Java 如何在Spring Boot中创建无限返回的请求

Java 如何在Spring Boot中创建无限返回的请求,java,spring,websocket,request,Java,Spring,Websocket,Request,我有一个带有用户通知的web应用程序(如facebook、twitter、instagram通知)。每次某个期限到期时,我都需要返回到前端通知,因此我的后端每次都必须检查是否有任何期限即将到期或已经到期。这就是为什么我想创建一个请求,例如每5分钟返回一次 我试过Spring@Schedule和WebSocket 使用时间表: @Scheduled(fixedDelay = 1000) @GetMapping(value = "/notification/get", produces =

我有一个带有用户通知的web应用程序(如facebook、twitter、instagram通知)。每次某个期限到期时,我都需要返回到前端通知,因此我的后端每次都必须检查是否有任何期限即将到期或已经到期。这就是为什么我想创建一个请求,例如每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);
    }
@Scheduled(fixedDelay=1000)
@GetMapping(value=“/notification/get”,products={MediaType.APPLICATION\u JSON\u value})
public ResponseEntity returnsNotification()引发InterruptedException{
睡眠(4000);
列表通知=seachNotifications();
返回新的响应状态(通知,HttpStatus.OK);
}
我的问题是,使用这段代码,我的日程安排不起作用,因此我的前端每次都必须调用请求


使用websocket我还不知道如何使用它。

您是否在spring应用程序中使用@EnableScheduling激活了@Scheduled

请比“有很多麻烦”更具体一些。更多。并显示一些代码。