Skip to content

HttpMessageConverters picks up converter beans for both client and server #48310

@bclozel

Description

@bclozel

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 ClientHttpMessageConvertersCustomizer and ServerHttpMessageConvertersCustomizer instances. 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).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions