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

废话不多说,上链接,官方配置的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;}}

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注