0

I am new to SpringBoot and looking for a way to Timeout when endpoint takes more than 3 seconds to return the response. I tried by adding the property "server.servlet.session.timeout", but still no luck. How to achieve this? Thanks.

@GetMapping("/api")
public Data getData(){

    Thread.sleep(10000);

    return ....;
}

Application.properties

server.servlet.session.timeout=3s
user15006167
  • 184
  • 1
  • 3
  • 12

1 Answers1

0

Not sure what your http client looks like. (RestTemplate/WebClient). But using WebClient this is how you can create TimeOut for your need.

HttpClient client = HttpClient.create()
  .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000);

Refer this for a detailed explanation:

https://www.baeldung.com/spring-webflux-timeout

Ajay Kumar
  • 2,906
  • 3
  • 23
  • 46