简体   繁体   English

Spring Boot假装异常

[英]Spring Boot feign exception

I am trying to make an API request with application / x-www-form-urlencoded. 我正在尝试使用应用程序/ x-www-form-urlencoded发出API请求。

Here is my feign client: 这是我的假客户:

 @Bean
public YandexDelivery yandexDelivery() {
    return Feign.builder()
            .client(new OkHttpClient())
            .encoder(new FormEncoder())
            .decoder(new GsonDecoder())
            .logger(new Slf4jLogger(YandexDelivery.class))
            .logLevel(Logger.Level.FULL)
            .target(YandexDelivery.class, "https://delivery.yandex.ru/api/last/searchDeliveryList");

}

Here is my interface: 这是我的界面:

public interface YandexDelivery {
@RequestLine("POST")
@Headers({"Content-Type: application/x-www-form-urlencoded"})
Delivery getDeliveryVariants(Map<String, ?> request);

} }

This is how I call: 这就是我所说的:

@Autowired
private YandexDelivery yandexDelivery;

@Override
public Delivery getDeliverysType(String cityFrom, String cityTo, Integer clientId, String deliveryType, Integer height, Integer indexCity, Integer length, Integer senderId, Integer weight, Integer width) {
    DeliveryVariantsModel model = new DeliveryVariantsModel(cityFrom, cityTo, clientId, deliveryType, height, indexCity, length, senderId, weight, width);
    HashMap<String, String> map = new HashMap<>();
    map.put("secret_key", model.getSecretKey());
    map.put("client_id", model.getClientId().toString());
    map.put("sender_id", model.getSenderId().toString());
    map.put("city_from", model.getCityFrom());
    map.put("city_to", model.getCityTo());
    map.put("weight", model.getWeight().toString());
    map.put("length", model.getLength().toString());
    map.put("width", model.getWidth().toString());
    map.put("height", model.getHeight().toString());
    map.put("delivery_type", model.getDeliveryType());
    map.put("index_city", model.getIndexCity().toString());
    return yandexDelivery.getDeliveryVariants(map);
}

And here is my mistake: 这是我的错误:

java.lang.ClassNotFoundException: feign.Request$Body

您是否没有依赖spring-cloud-starter-feign

I had the same problem. 我有同样的问题。 The fix was to set the correct spring cloud dependency fitting to the used Spring boot version. 解决方法是为使用的Spring引导版本设置正确的Spring Cloud依赖关系。 You can find the correct setting at https://start.spring.io/actuator/info in my case for Spring Boot version 2.1.2.RELEASE i had to use spring-cloud.version Greenwich.SR1 对于我的Spring Boot版本2.1.2,您可以在https://start.spring.io/actuator/info上找到正确的设置。发布我必须使用spring-cloud.version Greenwich.SR1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OAuth + Feign with Scheduled in Spring Boot - OAuth + Feign with Scheduled in Spring Boot 更新到 Spring Boot 1.5.8 和 Finchley/Edgware Spring Cloud 后的 Feign Exception 403 - Feign Exception 403 after updating to Spring Boot 1.5.8 and Finchley/Edgware Spring Cloud Feign 客户端总是在 Spring 启动/Crawler4j 应用程序中抛出 null 指针异常 - Feign client always throws a null pointer exception in a Spring boot/Crawler4j app 将Hystrix和Feign添加到Spring Boot项目 - Adding Hystrix and Feign to Spring Boot project Spring Boot - 线程 / Feign-Client / 消息 / Streamlistener - Spring boot - Threads / Feign-Client / Messaging / Streamlistener 如何使用 Spring Boot feign 客户端进行 Oauth2 身份验证? - How to use Spring Boot feign client for Oauth2 authentication? spring boot oauth2 feign 允许匿名请求 - spring boot oauth2 feign allow anonymous requests Spring Boot 2 - 自动装配服务时对 Feign 客户端的依赖不满意 - Spring Boot 2 - Unsatisfied dependency on Feign client when autowired for service 如何使用 postman 或 feign 客户端在 Spring 引导中将值设置为 @RequestAttribute - How to set value to @RequestAttribute in Spring boot using postman or feign client Feign客户端,Spring Boot应用程序和rx / Observable类未找到错误 - Feign Client, Spring Boot Application, and rx/Observable Class Not Found Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM