Ошибка появляется случайным образом во время вызовов API, и в журнале отображается следующее:
Код: Выделить всё
org.springframework.web.client.RestClientException: No suitable HttpMessageConverter found for response type [X] and content type [application/json]
After restarting the application, the issue typically does not resurface until the next release or redeployment.
The same issue does not occur in the local environment when I try to simulate load (I used tools to simulate high concurrency with 10,000 requests).
Код: Выделить всё
I have a custom RestTemplate bean defined in a configuration class, where I explicitly add MessageConverters, including MappingJackson2HttpMessageConverter to handle JSON responses.
The issue occurs despite ensuring that the RestTemplate is configured properly with converters at startup.
Код: Выделить всё
When I initialize RestTemplate in the configuration class, it shows 7 MessageConverters.
However, during runtime (when making an API call), I notice the RestTemplate has 16 MessageConverters, suggesting that converters are being added somewhere during the application lifecycle.
The RestTemplate is injected into the service using @Autowired, and no @Qualifier or additional RestTemplate beans are being used.
Код: Выделить всё
I excluded RestTemplateAutoConfiguration to avoid auto-configuration of RestTemplate, but the issue persists.
I’ve checked for multiple RestTemplate beans and made sure the correct instance is being used.
I added logging around RestTemplate initialization to track when the MessageConverters are being modified, but I can’t pinpoint the source of the change.
High concurrency tests locally don’t reproduce the issue, which mostly happens in production or staging environments.
Код: Выделить всё
The error message I see in the logs is:
org.springframework.web.client.RestClientException: No suitable HttpMessageConverter found for response type [X] and content type [application/json]
The HttpMessageConverter for application/json should be present (MappingJackson2HttpMessageConverter), but it appears to get lost or altered at some point during runtime.
Key Questions:
What could be causing additional MessageConverters to be added to the RestTemplate after it has been initialized?
Could concurrency or load affect the behavior of HttpMessageConverter, and how can I better reproduce this locally?
Is there a way to reinitialize the RestTemplate bean or the converters dynamically in case this issue arises, as the problem seems to go away after restarting the app?
Подробнее здесь: https://stackoverflow.com/questions/790 ... n-spring-b