提交 be6f985f 编写于 作者: Q qinyingjie

fix:feign的使用

上级 ea47eff3
......@@ -34,6 +34,13 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.7.RELEASE</version>
</dependency>
</dependencies>
<build>
......
......@@ -3,7 +3,10 @@ package com.kwan.springcloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
public class PortalApplication {
......
package com.kwan.springcloud.api;
import com.kwan.springcloud.response.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.Serializable;
/**
* 使用feign配置goods-service服务
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/10 13:45
*/
@FeignClient("goods-service/kwanGoodsInfo")
public interface ComputeClient {
@RequestMapping(method = RequestMethod.GET, value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
Result selectOne(@PathVariable Serializable id);
}
package com.kwan.springcloud.controller;
import com.kwan.springcloud.api.ComputeClient;
import com.kwan.springcloud.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.Serializable;
/**
* portal控制器
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/8 11:12
*/
@RestController
@RequestMapping("feign")
public class FeignController {
@Autowired
private ComputeClient computeClient;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping(value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result selectOne(@PathVariable Serializable id) {
//调用远程的controller
return computeClient.selectOne(id);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册