From d7abb067efa87eda7c37841d0273cd5af9966dc6 Mon Sep 17 00:00:00 2001 From: qinyingjie Date: Mon, 9 Jan 2023 21:22:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:eureka=E9=AB=98=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../springcloud/controller/PortalController.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java b/springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java index 3c955a4..4fcab8b 100644 --- a/springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java +++ b/springcloud-service-portal/src/main/java/com/kwan/springcloud/controller/PortalController.java @@ -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 forEntity = restTemplate.getForEntity(GOODS_URL + id, Result.class); + ResponseEntity forEntity = restTemplate.getForEntity(GOODS_URL_2 + id, Result.class); return Result.ok(forEntity); } } \ No newline at end of file -- GitLab