Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个场景,如果服务器发送的数据比预期的多,则需要关闭 http 连接。即在收到数据几秒钟后,我想自动关闭连接。这可行吗?
您可以在 RestTemplate 上指定超时。这样您就可以终止任何长时间运行的请求。
@Bean public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { return restTemplateBuilder .setConnectTimeout(...) .setReadTimeout(...) .build(); }