添加自定义消息转换器不覆盖默认转换器请使用extendMessageConverters
添加自定义会覆盖默认转换器使用configureMessageConverters
configureMessageConverters
/**
* Configure the {@link HttpMessageConverter HttpMessageConverters} to use for reading or writing
* to the body of the request or response. If no converters are added, a
* default list of converters is registered.
* <p><strong>Note</strong> that adding converters to the list, turns off
* default converter registration. To simply add a converter without impacting
* default registration, consider using the method
* {@link #extendMessageConverters(java.util.List)} instead.
* @param converters initially an empty list of converters
*/
default void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
}
意思是
配置HttpMessageConverters以用于读取或写入请求或响应的主体。如果未添加转换器,则会注册转换器的默认列表。请注意,向列表中添加转换器将关闭默认转换器注册。只需添加一个转换器而不影响默认注册,请考虑使用 extendMessageConverters
extendMessageConverters
/**
* A hook for extending or modifying the list of converters after it has been
* configured. This may be useful for example to allow default converters to
* be registered and then insert a custom converter through this method.
* @param converters the list of configured converters to extend.
* @since 4.1.3
*/
default void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
}
意思是
用于在配置转换器后扩展或修改转换器列表的钩子。这可能很有用,例如允许注册默认转换器,然后通过此方法插入自定义转换器。