fix:feign调用

上级 b8d18edd
......@@ -2,6 +2,7 @@ package com.kwan.springcloudalibaba;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
......@@ -16,6 +17,7 @@ public class NacosConsumerApplication {
@LoadBalanced
@Bean
@ConditionalOnMissingBean({RestTemplate.class})
public RestTemplate restTemplate() {
return new RestTemplate();
}
......
......@@ -47,7 +47,7 @@ public class ConsumerUserController {
ServiceInstance serviceInstance = loadBalancerClient.choose("nacos-server-producer");
String url = String.format("http://%s:%s/user/%s", "nacos-server-producer", serviceInstance.getPort(), id);
System.out.println("request url:" + url);
return Result.ok(restTemplate.getForObject(url, Object.class));
return Result.ok(restTemplate.getForObject(url, Result.class));
}
/**
......@@ -64,7 +64,7 @@ public class ConsumerUserController {
System.out.println("request url:" + url);
//必须要用新的RestTemplate
RestTemplate restTemplate = new RestTemplate();
return Result.ok(restTemplate.getForObject(url, Object.class));
return Result.ok(restTemplate.getForObject(url, Result.class));
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册