fix:feign调用

上级 2f646233
......@@ -14,10 +14,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
* @version : 2.2.0
* @date : 2023/1/10 13:45
*/
@FeignClient(value = "nacos-server-producer/user", fallback = ComputeClientHystrix.class)
//@FeignClient(value = "nacos-server-producer",path = "/user", fallback = ComputeClientHystrix.class)
@FeignClient(value = "nacos-server-producer", path = "/user")
public interface ComputeClient {
@RequestMapping(method = RequestMethod.GET, value = "{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
Result getUserById(@PathVariable Integer id);
@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
Result selectOne(@PathVariable Integer id);
}
package com.kwan.springcloudalibaba.api;
import com.kwan.springcloudalibaba.common.Result;
import org.springframework.stereotype.Component;
/**
* feign的降级
*
* @author : qinyingjie
* @version : 2.2.0
* @date : 2023/1/14 16:47
*/
@Component
public class ComputeClientHystrix implements ComputeClient {
@Override
public Result getUserById(Integer id) {
return Result.error("feign方式请求 服务不可用 请求失败");
}
}
//package com.kwan.springcloudalibaba.api;
//
//import com.kwan.springcloudalibaba.common.Result;
//import org.springframework.stereotype.Component;
//
///**
// * feign的降级
// *
// * @author : qinyingjie
// * @version : 2.2.0
// * @date : 2023/1/14 16:47
// */
//@Component
//public class ComputeClientHystrix implements ComputeClient {
// @Override
// public Result selectOne(Integer id) {
// return Result.error("feign方式请求 服务不可用 请求失败");
// }
//}
......@@ -21,14 +21,16 @@ public class ConsumerUserController {
/**
* http://127.0.0.1:8085/nacos/consumer/getUserById/1
* http://127.0.0.1:8085/nacos/consumer/1
* <p>
* http://localhost:9091/user/1
*
* @param id
* @return
*/
@GetMapping(value = "/getUserById/{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result getUserById(@PathVariable Integer id) {
return Result.ok(computeClient.getUserById(id));
return Result.ok(computeClient.selectOne(id));
}
/**
......
......@@ -6,6 +6,7 @@ import com.kwan.springcloudalibaba.entity.User;
import com.kwan.springcloudalibaba.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -26,16 +27,19 @@ public class UserController {
private IUserService userService;
/**
* http://127.0.0.1:9091/user/getUserById/1
* 通过主键查询单条数据
*
* @param id
* @return
* http://localhost:9091/user/1
*
* @param id 主键
* @return 单条数据
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Result getUserById(@PathVariable Integer id) {
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE)
public Result selectOne(@PathVariable Integer id) {
return Result.ok(userService.getUserById(id));
}
@RequestMapping(value = "/all", method = RequestMethod.GET)
public List<User> addAdvertise() {
log.info("测试日志={}", "success");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册