> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/76.-spring-mvc/76.4-customize-the-responsebody-rendering.md).

# 76.4 自定义@ResponseBody渲染

Spring使用`HttpMessageConverters`渲染`@ResponseBody`（或来自`@RestController`的响应）。你可以通过在Spring Boot上下文中添加该类型的beans来贡献其他的转换器。如果你添加的bean类型默认已经包含了（像用于JSON转换的`MappingJackson2HttpMessageConverter`），那它将替换默认的。Spring Boot提供一个`HttpMessageConverters`类型的bean，它有一些有用的方法可以访问默认的和用户增强的message转换器（比如你想要手动将它们注入到一个自定义的`RestTemplate`时就很有用）。

在通常的MVC用例中，任何你提供的`WebMvcConfigurer` beans通过覆盖`configureMessageConverters`方法也能贡献转换器，但不同于通常的MVC，你可以只提供你需要的转换器（因为Spring Boot使用相同的机制来贡献它默认的转换器）。最终，如果你通过提供自己的`@EnableWebMvc`注解覆盖Spring Boot默认的MVC配置，那你就可以完全控制，并使用来自`WebMvcConfigurationSupport`的`getMessageConverters`手动做任何事。

更多详情可参考[WebMvcAutoConfiguration](https://github.com/spring-projects/spring-boot/tree/v2.0.0.RELEASE/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java)源码。
