天天看點

Spring Cloud OpenFeign支援text/plain轉json問題pom.xmlFeignConfig.java參考:

問題

Spring Cloud OpenFeign預設是不會轉text/plain響應為json的。這裡需要這樣配置一下。讓其支援text内容能夠轉json。

pom.xml

<properties>
 <feign-jackson>12.1</feign-jackson>
</properties>
...
<dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-jackson</artifactId>
    <version>${feign-jackson}</version>
</dependency>
           

FeignConfig.java

package com.xxxx.configurer;

import feign.codec.Decoder;
import feign.jackson.JacksonDecoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignConfig {
    @Bean
    public Decoder feignDecoder() {
        return new JacksonDecoder();
    }
}

           

參考:

  • springboot: no suitable HttpMessageConverter found for response
  • How to set custom Jackson ObjectMapper with Spring Cloud Netflix Feign