Springboot - RestController 中有 5 秒睡眠时出现 405 错误

问题描述 投票:0回答:0

我在 Springboot 应用程序中使用 RestController。 在控制器方法中,我将 Thread.sleep 放置 5 秒。但是当我从 PostMan 尝试时,它立即显示 405 错误,但 5 秒后它到达控制器断点。客户端应用程序也会发生同样的情况,与邮递员无关。有人遇到过这种情况吗?我被困在这一点上。如果去掉睡眠,它就可以正常工作。为什么它不等待 5 秒并立即抛出 405..请帮忙..

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;
    

    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public List<User> getAllUsers() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("In getAllUsers");
        return userService.findAllUsers();
    }
}

我通过API网关访问该服务,9191是端口。请找到 api 网关的 yaml。如果直接访问用户服务就不存在这个问题。也不知道为什么在用户服务中睡眠时显示 405,并且在没有睡眠时没有 405 时可以正常工作。

eureka:
  instance:
    client:
      serviceUrl:
        defaultZone: http://localhost:8761/eureka/
management:
  endpoints:
    web:
      exposure:
        include: '*'
server:
  port: 9191
spring:
  application:
    name: API-GATEWAY
  cloud:
    gateway:
      httpclient:
        connect-timeout: 10000
        response-timeout: 7s
      routes:
        -   filters:
              -   args:
                    fallbackUri: forward:/fallback/userServiceFallback
                    name: userServiceCircuitBreaker
                  name: CircuitBreaker
            id: USER-SERVICE
            predicates:
              - Path=/user/*
            uri: lb://USER-SERVICE
  main:
    web-application-type: reactive
java spring-boot spring-restcontroller
© www.soinside.com 2019 - 2024. All rights reserved.