Skip to content

Skip Jaxb2RootElementHttpMessageConverter auto-detection in HttpMessageConverters #36302

@bclozel

Description

@bclozel

Currently, the Jaxb2RootElementHttpMessageConverter is auto-detected by HttpMessageConverters when the registerDefaults() option is enabled (as it's always the case for the MVC infrastructure).

We received consistent feedback, saying that:

  1. classpath detection is not really useful because jakarta.xml.bind.Binder is often brought transitively at runtime (for example, hibernate-core)
  2. the nature of that message converter requires extensive runtime checks to know whether it should be used

As a result, we should disable its auto-detection and let users register it manually if they intend to use it in their applications.

In a typical Spring application, this is as a easy as:

@Configuration(proxyBeanMethods = false)
class JaxbConverterConfiguration implements WebMvcConfigurer {

	@Override
	public void configureMessageConverters(HttpMessageConverters.ServerBuilder builder) {
		builder.withXmlConverter(new Jaxb2RootElementHttpMessageConverter());
	}
}

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions