Spring Cloud Greenwich.SR1 中使用Feign作为服务代理类需要进行如下配置:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
@Configuration
public class FeignConfig {
@Bean
public Encoder formEncoder() {
return new SpringFormEncoder();
}
@Bean
public feign.Logger.Level loggerLevel() {
return feign.Logger.Level.FULL;
}
}
因为默认Feign对于对象,无论是什么请求,都会把转换成Json提交,所以需要指定Content-Type,在Feign接口中参照如下注解:
@PostMapping(value = "", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)