官术网_书友最值得收藏!

How to do it...

There are a number of ways in which we can configure converters. It all depends on which one you prefer or how much control you want to achieve.

  1. Let's add ByteArrayHttpMessageConverter as @Bean to our WebConfiguration class in the following manner:
@Bean 
public  
  ByteArrayHttpMessageConverter  
    byteArrayHttpMessageConverter() { 
  return new ByteArrayHttpMessageConverter(); 
} 
  1. Another way to achieve this is to override the configureMessageConverters method in the WebConfiguration class, which extends WebMvcConfigurerAdapter, defining such a method as follows:
@Override 
public void configureMessageConverters
(List<HttpMessageConverter<?>> converters) { converters.add(new ByteArrayHttpMessageConverter()); }
  1. If you want to have a bit more control, we can override the extendMessageConverters method in the following way:
@Override 
public void extendMessageConverters
(List<HttpMessageConverter<?>> converters) { converters.clear(); converters.add(new ByteArrayHttpMessageConverter()); }
主站蜘蛛池模板: 兴业县| 梨树县| 武定县| 安新县| 东台市| 博野县| 宁津县| 齐齐哈尔市| 丰镇市| 剑阁县| 望奎县| 龙里县| 固阳县| 班玛县| 开化县| 江津市| 阿克陶县| 商丘市| 博乐市| 丹东市| 双桥区| 宾阳县| 精河县| 甘德县| 新源县| 娱乐| 库伦旗| 萍乡市| 鄱阳县| 郓城县| 汝阳县| 鹿邑县| 依安县| 新昌县| 古田县| 黑河市| 西平县| 读书| 贵南县| 江北区| 柳江县|