Spring Boot feign exception

I am trying to make an API request with application / x-www-form-urlencoded.

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

Upvotes: 0

Views: 3031

Answers (2)

Uli
Uli

Reputation: 1

I had the same problem. The fix was to set the correct spring cloud dependency fitting to the used Spring boot version. 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

Upvotes: 0

Doo Su Jung
Doo Su Jung

Reputation: 57

Did you leave out the spring-cloud-starter-feign in dependency?

Upvotes: 1

Related Questions