使用RestTemplate时获取UnknownHostException正在解析春季云中的URL(SPRING_BOOT:2.0.3)

时间:2018-07-22 19:36:20

标签: spring spring-boot spring-cloud

客户端配置

spring: application: name: ABCProductService profiles: CLOUD server: port: 9000 eureka: client: registerWithEureka: true fetchRegistry: true region: default serviceUrl: defaultZone: http://localhost:3000/eureka instance: preferIpAddress: false

RestTemplate配置:

@Bean
@LoadBalanced
public RestTemplate getTemplate() {
    return new RestTemplate();
}

但是在解析网址时会显示异常

@Autowired
private RestTemplate template;

@GetMapping("/ABC/{productid}")
public String getProductPrice(@PathVariable String productid) {
    return template.getForObject("http://ABCPaymentService/v1/"+productid+"/getPrice", String.class);
}

正在获取:java.net.UnknownHostException: ABCPaymentService

有人可以帮我吗

0 个答案:

没有答案