Java 我们正在使用微服务。如何增加特定springboot api的超时?

Java 我们正在使用微服务。如何增加特定springboot api的超时?,java,spring-boot,microservices,ribbon,Java,Spring Boot,Microservices,Ribbon,我想在控制器级别增加API的超时时间。对于所有API,我们可以在我的yml文件中提到以下内容: ribbon: ReadTimeout: 30000 ConnectTimeout: 30000 但是我想为一个特定的API增加超时。因为它是一个很长的过程API。我们如何才能做到这一点 @GetMapping(value = { "", "/" }) public ResponseEntity<Page<DBInventoryMa

我想在控制器级别增加API的超时时间。对于所有API,我们可以在我的yml文件中提到以下内容:

ribbon:
  ReadTimeout: 30000
  ConnectTimeout: 30000
但是我想为一个特定的API增加超时。因为它是一个很长的过程API。我们如何才能做到这一点

@GetMapping(value = { "", "/" })
    public ResponseEntity<Page<DBInventoryMasterEntity>> fetch() {
        Page<DBInventoryMasterEntity> returnList = null;
            returnList = inventoryService.findByCustomerCode();
        return ResponseEntity.ok(returnList);
    }
@GetMapping(值={“,”/“})
公共响应获取(){
页面返回列表=空;
returnList=inventoryService.findByCustomerCode();
返回响应正确(返回列表);
}

您可以尝试以下两种方法:

  • 返回一个可调用的
    。见答案
  • 使用@Transactional注释,该注释采用超时(以秒为单位)参数
  • @GetMapping(值={“,”/“})
    @定时
    @事务(超时=120)//2分钟
    公共响应获取(){
    //你的代码
    }
    
    它会覆盖功能区超时吗?
        @GetMapping(value = { "", "/" })
        @Timed
        @Transactional(timeout = 120)  // 2 minutes
        public ResponseEntity<Page<DBInventoryMasterEntity>> fetch() {
            // your code
        }