学习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.onstant.SecurityConstants;
import com.util.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(contextId = "remoteDemoService", value = "pig-demo-biz",
fallbackFactory = RemoteDemoServiceFallbackFactory.class)
springcloud难学吗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.util.R;
public class RemoteDemoServiceFallbackImpl implements RemoteDemoService {
@lombok.Setter
private static Throwable cause;
@Override
public R<Boolean> saveLog(SysLog sysLog, String from) {
System.out.println("======调⽤到feign=====");
System.out.Id());
return new R();
}
}
package com.pig4cloud.pig.demo.api.feign;
import org.springframework.cloud.openfeign.FallbackFactory;
public class RemoteDemoServiceFallbackFactory implements FallbackFactory<RemoteDemoService> {
@Override
public RemoteDemoServiceFallbackImpl create(Throwable throwable) {
RemoteDemoServiceFallbackImpl remotedemoServiceFallback = new RemoteDemoServiceFallbackImpl();
RemoteDemoServiceFallbackImpl.setCause(throwable);
return remotedemoServiceFallback;
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。