|
@@ -0,0 +1,37 @@
|
|
|
|
|
+package space.anyi.user.service;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.cloud.openfeign.FallbackFactory;
|
|
|
|
|
+import org.springframework.cloud.openfeign.FeignClient;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
+import space.anyi.user.model.User;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @ProjectName: springboot-autoconfiguration-learn
|
|
|
|
|
+ * @FileName: UserService
|
|
|
|
|
+ * @Author: 杨逸
|
|
|
|
|
+ * @Data:2025/10/13 21:04
|
|
|
|
|
+ * @Description:
|
|
|
|
|
+ */
|
|
|
|
|
+@FeignClient(name = "ms-user-web",url = "${ms-user.url:127.0.0.1:8080}",fallbackFactory = UserService.UserCallbackFactory.class)
|
|
|
|
|
+public interface UserService {
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @GetMapping("/getUser/{id}")
|
|
|
|
|
+ User getUserById(@PathVariable("id") Long id);
|
|
|
|
|
+
|
|
|
|
|
+ //定义一个回调工厂类
|
|
|
|
|
+ @Component
|
|
|
|
|
+ public static class UserCallbackFactory implements FallbackFactory<UserService> {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public UserService create(Throwable cause) {
|
|
|
|
|
+ return new UserService() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public User getUserById(Long id) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|