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

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()); }
主站蜘蛛池模板: 临江市| 马山县| 荣成市| 金华市| 平潭县| 龙门县| 柳州市| 兴山县| 临猗县| 益阳市| 永定县| 常熟市| 龙海市| 吴川市| 民和| 海晏县| 凤冈县| 饶河县| 石林| 长汀县| 甘洛县| 邳州市| 永平县| 五指山市| 罗源县| 尉氏县| 木兰县| 华阴市| 高唐县| 蒲城县| 建宁县| 吉木萨尔县| 阜康市| 浦东新区| 内黄县| 靖远县| 康马县| 禹城市| 定州市| 阿城市| 雷州市|