提交 d7abb067 编写于 作者: Q qinyingjie

fix:eureka高可用

上级 81c332f0
......@@ -2,6 +2,7 @@ package com.kwan.springcloud.controller;
import com.kwan.springcloud.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......@@ -22,7 +23,16 @@ import java.io.Serializable;
@RestController
@RequestMapping("portal")
public class PortalController {
/**
* http直接访问
*/
private static final String GOODS_URL = "http://localhost:9100/kwanGoodsInfo/";
/**
* eureka访问
*/
private static final String GOODS_URL_2 = "http://goods-service/kwanGoodsInfo/";
/**
* 服务对象
*/
......@@ -35,10 +45,10 @@ public class PortalController {
* @param id 主键
* @return 单条数据
*/
@GetMapping("{id}")
@GetMapping(value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result selectOne(@PathVariable Serializable id) {
//调用远程的controller
ResponseEntity<Result> forEntity = restTemplate.getForEntity(GOODS_URL + id, Result.class);
ResponseEntity<Result> forEntity = restTemplate.getForEntity(GOODS_URL_2 + id, Result.class);
return Result.ok(forEntity);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册