天天看点

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