Spring Boot REST API - request timeout?
You need to return a Callable<>
if you want spring.mvc.async.request-timeout=5000
to work.
@RequestMapping(method = RequestMethod.GET)
public Callable<String> getFoobar() throws InterruptedException {
return new Callable<String>() {
@Override
public String call() throws Exception {
Thread.sleep(8000); //this will cause a timeout
return "foobar";
}
};
}
Spring Boot Application - what is default timeout for any rest API endpoint or a easy config to control all endpoint timeout
I agree all above options and tried below option in my spring boot application. It works perfectly fine now. Below is the code sample as a bean. Now just need to @Autowire
RestTemplate
wherever(java class
) I need it.
@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setConnectTimeout(15000);
((SimpleClientHttpRequestFactory) restTemplate.getRequestFactory()).setReadTimeout(15000);
return restTemplate;
}
Related Topics
Jax-Rs - How to Return JSON and Http Status Code Together
Difference Between List, List<>, List<T>, List<E>, and List<Object>
Difference in System. Exit(0) , System.Exit(-1), System.Exit(1 ) in Java
What's Alternative to Singleton
Populating Spring @Value During Unit Test
How to Fetch Fetchtype.Lazy Associations with JPA and Hibernate in a Spring Controller
Maven Compile with Multiple Src Directories
What Is a Covariant Return Type
Bytebuffer.Allocate() VS. Bytebuffer.Allocatedirect()
How to Write Logs in Text File When Using Java.Util.Logging.Logger
Correct Way to Close Nested Streams and Writers in Java
Create a Maven Project in Eclipse Complains "Could Not Resolve Archetype"
Creating a Bundle Jar with Ant
Communication Between Two Separate Java Desktop Applications