Does Spring create new thread per request in rest controllers?

It’s blocking in the sense that it blocks one thread: the thread taken out of the pool of threads by the servlet container (Tomcat, Jetty, etc., not Spring) to handle your request. Fortunately, many threads are used concurrently to handle requests, otherwise the performance of any Java web application would be dramatic. If you have, … Read more

Spring RestTemplate and generic types ParameterizedTypeReference collections like List

I worked around this using the following generic method: public <T> List<T> exchangeAsList(String uri, ParameterizedTypeReference<List<T>> responseType) { return restTemplate.exchange(uri, HttpMethod.GET, null, responseType).getBody(); } Then I could call: List<MyDto> dtoList = this.exchangeAsList(“http://my/url”, new ParameterizedTypeReference<List<MyDto>>() {}); This did burden my callers with having to specify the ParameterizedTypeReference when calling, but meant that I did not have to … Read more

Reading HTTP headers in a Spring REST controller

The error that you get does not seem to be related to the RequestHeader. And you seem to be confusing Spring REST services with JAX-RS, your method signature should be something like: @RequestMapping(produces = “application/json”, method = RequestMethod.GET, value = “data”) @ResponseBody public ResponseEntity<Data> getData(@RequestHeader(value=”User-Agent”) String userAgent, @RequestParam(value = “ID”, defaultValue = “”) String id) … Read more

Spring Boot – How to log all requests and responses with exceptions in single place?

Don’t write any Interceptors, Filters, Components, Aspects, etc., this is a very common problem and has been solved many times over. Spring Boot has a modules called Actuator, which provides HTTP request logging out of the box. There’s an endpoint mapped to /trace (SB1.x) or /actuator/httptrace (SB2.0+) which will show you last 100 HTTP requests. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)