使用以下代码时,我得到了ClassCastException: Stringcannot be cast to org.springframework.http.ResponseEntity

@Autowired
private  ClientService clientService;

public void methodA() {
    String url = ...
    ResponseEntity<String> resEntity = clientService.callService(url);
}

最佳答案

该错误表示:

这个说法

clientService.callService(url);


正在调用方法callService,该方法将返回String类的对象,该对象的类型不同于那里的ResponseEntity,因此无效:

ResponseEntity resEntity = clientService.callService(url);

09-25 18:07