springboot服务之间调用

1:

RestTemplate restTemplate = new RestTemplate();
wareMessage.setSystemEmployee(systemEmployee);
wareMessage.setInShop(wareMessage.getInShop());
wareMessage.setIsSynch(1);
/*System.out.println(JSONObject.toJSONString(wareMessageListVo));
wareMessageListVo.setConditionsToAdd(0);*/
HttpHeaders requestHeaders = new HttpHeaders();

HttpEntity requestEntity = new HttpEntity<>(wareMessage, requestHeaders);  //outWarehouseReq为正常要传入的参数  将请求头 请求体放入HttpEntity中
String jsonReturn = restTemplate.postForObject(PRODUCT_URL+"/product/insertTproductSync", requestEntity, String.class);
System.out.println(jsonReturn);
ObjectMapper objectMapper = new ObjectMapper();

 

2:

import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
ServiceInstance instance = this.loadBalancerClient.choose("service-product");
URI uri = URI.create(String.format("http://%s:%s/product/getByProduct/", instance.getHost(), instance.getPort()));
String s = restTemplate.postForObject(uri, wareMessageListVo, String.class);
System.out.println("s = " + s);

你可能感兴趣的:(java)