我正在尝试使用 application/x-www-form-urlencoded 发出 API 请求。这是我的假客户: @Beanpublic 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");}这是我的界面:public interface YandexDelivery {@RequestLine("POST")@Headers({"Content-Type: application/x-www-form-urlencoded"})Delivery getDeliveryVariants(Map<String, ?> request);}这就是我所说的:@Autowiredprivate YandexDelivery yandexDelivery;@Overridepublic 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);}这是我的错误:java.lang.ClassNotFoundException: feign.Request$Body
2 回答
慕少森
TA贡献2019条经验 获得超9个赞
我有同样的问题。修复方法是为使用的 Spring 引导版本设置正确的 Spring Cloud 依赖项。在我的情况下,您可以在https://start.spring.io/actuator/info找到正确的设置, 对于 Spring Boot 版本 2.1.2.RELEASE 我必须使用 spring-cloud.version Greenwich.SR1
添加回答
举报
0/150
提交
取消