diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java index bcf806353..6a95024bf 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java @@ -20,7 +20,7 @@ package com.pig4cloud.pigx.admin.api.feign; import com.pig4cloud.pigx.admin.api.dto.UserInfo; -import com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl; +import com.pig4cloud.pigx.admin.api.feign.factory.RemoteUserServiceFallbackFactory; import com.pig4cloud.pigx.common.core.constant.ServiceNameConstant; import com.pig4cloud.pigx.common.core.util.R; import org.springframework.cloud.openfeign.FeignClient; @@ -32,7 +32,7 @@ import org.springframework.web.bind.annotation.RequestHeader; * @author lengleng * @date 2018/6/22 */ -@FeignClient(value = ServiceNameConstant.UMPS_SERVICE, fallback = RemoteUserServiceFallbackImpl.class) +@FeignClient(value = ServiceNameConstant.UMPS_SERVICE, fallbackFactory = RemoteUserServiceFallbackFactory.class) public interface RemoteUserService { /** * 通过用户名查询用户、角色信息 diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/factory/RemoteUserServiceFallbackFactory.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/factory/RemoteUserServiceFallbackFactory.java new file mode 100644 index 000000000..93dbb02b4 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/factory/RemoteUserServiceFallbackFactory.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.api.feign.factory; + +import com.pig4cloud.pigx.admin.api.feign.RemoteUserService; +import com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl; +import feign.hystrix.FallbackFactory; +import org.springframework.stereotype.Component; + +/** + * @author lengleng + * @date 2018/9/1 + */ +@Component +public class RemoteUserServiceFallbackFactory implements FallbackFactory { + + @Override + public RemoteUserService create(Throwable throwable) { + RemoteUserServiceFallbackImpl remoteUserServiceFallback = new RemoteUserServiceFallbackImpl(); + remoteUserServiceFallback.setCause(throwable); + return remoteUserServiceFallback; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java index 7f501bca0..37ebaba44 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java @@ -22,6 +22,7 @@ package com.pig4cloud.pigx.admin.api.feign.fallback; import com.pig4cloud.pigx.admin.api.dto.UserInfo; import com.pig4cloud.pigx.admin.api.feign.RemoteUserService; import com.pig4cloud.pigx.common.core.util.R; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -32,6 +33,9 @@ import org.springframework.stereotype.Component; @Slf4j @Component public class RemoteUserServiceFallbackImpl implements RemoteUserService { + @Setter + private Throwable cause; + /** * 通过用户名查询用户、角色信息 * @@ -41,7 +45,7 @@ public class RemoteUserServiceFallbackImpl implements RemoteUserService { */ @Override public R info(String username, String from) { - log.error("feign 查询用户信息失败:{}", username); + log.error("feign 查询用户信息失败:{}", username, cause); return null; } @@ -53,7 +57,7 @@ public class RemoteUserServiceFallbackImpl implements RemoteUserService { */ @Override public R social(String inStr) { - log.error("feign 查询用户信息失败:{}", inStr); + log.error("feign 查询用户信息失败:{}", inStr, cause); return null; } } diff --git a/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.factories b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.factories index d11d4b57c..cc68aecba 100644 --- a/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.factories +++ b/pigx-upms/pigx-upms-api/src/main/resources/META-INF/spring.factories @@ -1,3 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ com.pig4cloud.pigx.admin.api.feign.fallback.RemoteUserServiceFallbackImpl,\ - com.pig4cloud.pigx.admin.api.feign.fallback.RemoteLogServiceFallbackImpl\ + com.pig4cloud.pigx.admin.api.feign.fallback.RemoteLogServiceFallbackImpl,\ + com.pig4cloud.pigx.admin.api.feign.factory.RemoteUserServiceFallbackFactory