相关文章推荐
力能扛鼎的领结  ·  C语言 ...·  1 年前    · 
冲动的鸵鸟  ·  Ubuntu 10.10 安装 ...·  1 年前    · 
任性的钥匙扣  ·  python svn info ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm seeing an error message when trying to run a sample program on Sprint boot, while using Eclipse based Spring Suite. I have JDK11 installed in the mac that I'm currently using

Error Message: The method exchange(URI, HttpMethod, HttpEntity, Class) in the type RestTemplate is not applicable for the arguments (URI, Http.HttpMethod, HttpEntity, Class)

Initially the exchange method was in this form: exchange(url,HttpMethod.GET, null, String.class);

When url was a String. Since the method required URI object, I changed the code. Also in my hunt for a solution, I also converted the null parameter to an object.

public String secondWayOfCalling() {
    RestTemplate template = builder.build();
    List<ServiceInstance> instances= clientOnly.getInstances("client-service-name");
    URI uri = instances.get(0).getUri();
    ResponseEntity<String> entity = template.exchange(uri, HttpMethod.GET, 
            new HttpEntity<String>("parameters"), String.class);
    return entity.getBody();

Your code looks correct, if you get such an error I am pretty sure you messed up with your imports, check that your used classes come from following packages:

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import java.net.URI;

I bet your URI class comes from a wrong one.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.