首页 > 编程知识 正文

pigx框架如何使用教程,pigx框架如何

时间:2023-05-04 10:13:49 阅读:195031 作者:4377

废话不多说,上链接,官方配置的feign文档有误

feign调用及服务间鉴权 · 语雀

其中错误点在于(不计包名的问题)

 实际配置要这样才能正常使用 spring.factories

 调用feign

private final RemoteDemoService remoteDemoService;/** * testFeign * @return */@ApiOperation(value = "testFeign", notes = "testFeign")@GetMapping("/testFeign" )public R testFeign() {com.pig4cloud.pig.demo.api.feign.SysLog sysLog = new com.pig4cloud.pig.demo.api.feign.SysLog();sysLog.setId(1l);return R.ok(remoteDemoService.saveLog(sysLog, FROM_IN));} package com.pig4cloud.pig.demo.api.feign;import com.pig4cloud.pig.common.core.constant.SecurityConstants;import com.pig4cloud.pig.common.core.util.R;import org.springframework.cloud.openfeign.FeignClient;import org.springframework.web.bind.annotation.*;@FeignClient(contextId = "remoteDemoService", value = "pig-demo-biz",fallbackFactory = RemoteDemoServiceFallbackFactory.class)public interface RemoteDemoService {/** * 保存日志 * @param sysLog 日志实体 * @param from 内部调用标志 * @return succes、false */@PostMapping("/log")R<Boolean> saveLog(@RequestBody SysLog sysLog, @RequestHeader(SecurityConstants.FROM) String from);}

package com.pig4cloud.pig.demo.api.feign;import com.pig4cloud.pig.common.core.util.R;public class RemoteDemoServiceFallbackImpl implements RemoteDemoService {@lombok.Setterprivate static Throwable cause;@Overridepublic R<Boolean> saveLog(SysLog sysLog, String from) {System.out.println("======调用到feign=====");System.out.println(sysLog.getId());return new R();}} package com.pig4cloud.pig.demo.api.feign;import org.springframework.cloud.openfeign.FallbackFactory;public class RemoteDemoServiceFallbackFactory implements FallbackFactory<RemoteDemoService> {@Overridepublic RemoteDemoServiceFallbackImpl create(Throwable throwable) {RemoteDemoServiceFallbackImpl remotedemoServiceFallback = new RemoteDemoServiceFallbackImpl();RemoteDemoServiceFallbackImpl.setCause(throwable);return remotedemoServiceFallback;}}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。