-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
In Spring Boot 3.x, Boot's org.springframework.boot.http.converter.autoconfigure.HttpMessageConverters was collecting all converter beans from the context and using heuristics for their relative ordering or overriding. This HttpMessageConverters instance was used for both client and server infrastructure. This approach had clear drawbacks because it was not flexible enough as the client/server needs are different, we were overriding Framework's opinions, and wasting memory because we were creating multiple instances of the same thing at startup.
In Spring Boot 4.0, we are now using Framework's org.springframework.http.converter.HttpMessageConverters to configure converters on the client and server infrastructure, separately. This solves most of the problems listed above. But currently we keep collecting all converters beans from the context and we apply them with DefaultServerHttpMessageConvertersCustomizer and DefaultClientHttpMessageConvertersCustomizer.
As seen in #48302, using converters from the application context and applying them to both client and server is not correct and causes issues.
We have decided to revisit this situation and instead:
- not contribute converters to the application context in our auto-configurations, and instead contribute
ClientHttpMessageConvertersCustomizerandServerHttpMessageConvertersCustomizerinstances. In most cases, the auto-configured converters can be applied to both client and server. - we will keep collecting converter beans from the application context for now, and revisit the situation after evaluating the changes in our ecosystem. Ideally, if the application contributes converters this should be done more consciously and deliberately.
- document the fact that applications should contribute customizers that will explicitly configure converters for client and/or server infrastructure, and where this converter should be configured in the
HttpMessageConverters(overriding a "default" one, or setting it ahead of the default ones as custom).