File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change 11### 71.4 自定义@ResponseBody 渲染
22
3- Spring使用HttpMessageConverters渲染 ` @ResponseBody ` (或来自` @RestController ` 的响应)。 你可以通过在Spring Boot上下文中添加该类型的beans来贡献其他的转换器。如果你添加的bean类型默认已经包含了(像用于JSON转换的MappingJackson2HttpMessageConverter ),那它将替换默认的。Spring Boot提供一个方便的HttpMessageConverters类型的bean ,它有一些有用的方法可以访问默认的和用户增强的message转换器(有用, 比如你想要手动将它们注入到一个自定义的` RestTemplate ` )。
3+ Spring使用 ` HttpMessageConverters ` 渲染 ` @ResponseBody ` (或来自` @RestController ` 的响应), 你可以通过在Spring Boot上下文中添加该类型的beans来贡献其他的转换器。如果你添加的bean类型默认已经包含了(像用于JSON转换的 ` MappingJackson2HttpMessageConverter ` ),那它将替换默认的。Spring Boot提供一个方便的 ` HttpMessageConverters ` 类型的bean ,它有一些有用的方法可以访问默认的和用户增强的message转换器(比如你想要手动将它们注入到一个自定义的` RestTemplate ` 时就很有用 )。
44
5- 在通常的MVC用例中,任何你提供的WebMvcConfigurerAdapter beans通过覆盖configureMessageConverters方法也能贡献转换器 ,但不同于通常的MVC,你可以只提供你需要的转换器(因为Spring Boot使用相同的机制来贡献它默认的转换器)。最终,如果你通过提供自己的` @EnableWebMvc ` 注解覆盖Spring Boot默认的MVC配置,那你就可以完全控制,并使用来自WebMvcConfigurationSupport的getMessageConverters手动做任何事 。
5+ 在通常的MVC用例中,任何你提供的 ` WebMvcConfigurerAdapter ` beans通过覆盖 ` configureMessageConverters ` 方法也能贡献转换器 ,但不同于通常的MVC,你可以只提供你需要的转换器(因为Spring Boot使用相同的机制来贡献它默认的转换器)。最终,如果你通过提供自己的` @EnableWebMvc ` 注解覆盖Spring Boot默认的MVC配置,那你就可以完全控制,并使用来自 ` WebMvcConfigurationSupport ` 的 ` getMessageConverters ` 手动做任何事 。
66
7- 具体参考 [ WebMvcAutoConfiguration] ( http ://github.com/spring-projects/spring-boot/tree/master /spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java) 源码。
7+ 更多详情可参考 [ WebMvcAutoConfiguration] ( https ://github.com/spring-projects/spring-boot/tree/v1.4.1.RELEASE /spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java) 源码。
You can’t perform that action at this time.
0 commit comments