- Spring Boot 2.0 Cookbook(Second Edition)
- Alex Antonov
- 118字
- 2021-06-24 19:24:41
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.
- Let's add ByteArrayHttpMessageConverter as @Bean to our WebConfiguration class in the following manner:
@Bean public ByteArrayHttpMessageConverter byteArrayHttpMessageConverter() { return new ByteArrayHttpMessageConverter(); }
- 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()); }
- 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()); }
推薦閱讀
- Python數據挖掘:入門、進階與實用案例分析
- Voice Application Development for Android
- 使用GitOps實現Kubernetes的持續部署:模式、流程及工具
- 圖解機器學習算法
- 軟件成本度量國家標準實施指南:理論、方法與實踐
- Starling Game Development Essentials
- Learning Proxmox VE
- MATLAB Graphics and Data Visualization Cookbook
- INSTANT Apple iBooks How-to
- Python數據分析與數據化運營
- SAS金融數據挖掘與建模:系統方法與案例解析
- 爬蟲實戰:從數據到產品
- Swift Functional Programming(Second Edition)
- 數據中心UPS系統運維
- 一本書讀懂區塊鏈(第2版)