springspring-bootfeign

java.lang.IllegalStateException: Method has too many Body parameters


@FeignClient(name = "external-notifications")
public interface NotificationsClient {

    @PostMapping(value = {"/"}, consumes = {"application/json"}, produces = {"application/json"})
    Response sendNotification(String token, NotificationRequest request);
}

DTO:

public class NotificationRequest {
    private String city;
    private String town;
    private Boolean registered;
    private Set<Media> media;
    private UserInfo userInfo;
    private NotificationInfo notificationInfo;
    private List<Recipient> recipient;
    ....
    // getters and setters 

}

...
@Autowired
private NotificationsClient notificationsClient;

.sendNotification("user", notificationRequest);

....

I get error:

Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract com.NotificationResponse com.NotificationsClient.sendNotification(java.lang.String,com.NotificationRequest)
Warnings:
- 
    at feign.Util.checkState(Util.java:136) ~[feign-core-11.10.jar:na]

How I can fix this issue?


Solution

  • A request has only one body. If you have multiple parameters, specify argument types using the correct annotations:

    @PostMapping(value = {"/"}, consumes = {"application/json"}, produces = {"application/json"})
    Response sendNotification(@RequestParam String token, @RequestBody NotificationRequest request);
    

    If you want both to be a part of the request body, wrap them in a different object.