FeignClient重复调用远程方法

时间:2017-07-03 08:08:51

标签: java

我希望使用feignclient来调用一个远程方法,但是远程方法是执行重复,这是我的代码(我不擅长英语,所以很有魅力)

@ViewScoped
@ManagedBean
@Named("cdProductTemplateView")
public class CdProductTemplateView extends BaseView {
    public void cdPost() {
 //cdProTempContext,just a bean
    cdProductClient.cdPost(cdProTempContext);
}

}

客户端:

@FeignClient(value = "service", path = "/cdproduct")
public interface CdProductClient {
@RequestMapping("/cdPost")
CdProduct cdPost(@RequestBody CdProductTemplateContext 
     cdProTempContext) throws BusinessException, SystemException;
}

控制器:

    @RequestMapping("/cdproduct")
    @RestController
    public class CdProductController{
        public CdProduct cdPostProduct(CdProductTemplateContext cdProTempContext, String resPath)
                throws BusinessException, SystemException {

            return cdProductService.cdPostProduct(cdProTempContext, resPath);
        }
        @RequestMapping("/cdPost")
        public CdProduct cdPost(@RequestBody CdProductTemplateContext cdProTempContext, HttpServletRequest request) {
            return cdPostProduct(cdProTempContext, resPath);
        }
    }

serviceImpl:

    @Named("cdProductService")
    public class CdProductServiceImpl implements CdProductService {
        @Override
        public CdProduct cdPostProduct(CdProductTemplateContext 
          cdProTempContext, String resPath) throws BusinessException, SystemException {
        //proPkgRequset: a bean ProductPackageRequest 
         cdProService.submitProductPackage(proPkgRequset);
         //this just invoke method(ICDMarketplaceAPIService.submitProductPackage )

        }
    }

ICDMarketplaceAPIService

@WebService(targetNamespace = "http://www.***.com", name = "IMarketplaceAPIService")
@XmlSeeAlso({ObjectFactory.class})
public interface  ICDMarketplaceAPIService {
    @WebMethod(operationName = "SubmitProductPackage")
    @Action(input = "http://www.***.com/IMarketplaceAPIService/SubmitProductPackage", output = "http://www.***.com/IMarketplaceAPIService/SubmitProductPackageResponse")
    @RequestWrapper(localName = "SubmitProductPackage", targetNamespace = "http://www.***.com", className = "SubmitProductPackage")
    @ResponseWrapper(localName = "SubmitProductPackageResponse", targetNamespace = "http://www.***.com", className = "SubmitProductPackageResponse")
    @WebResult(name = "SubmitProductPackageResult", targetNamespace = "http://www.***.com")
    public ProductIntegrationReportMessage submitProductPackage(
            @WebParam(name = "headerMessage", targetNamespace = "http://www.***.com")
                    HeaderMessage headerMessage,
            @WebParam(name = "productPackageRequest", targetNamespace = "http://www.***.com")
                    ProductPackageRequest productPackageRequest
    );
}

当客户端调用远程方法时,远程方法(controller.cdPost,它执行重复),但如果我删除方法(ICDMarketplaceAPIService.submitProductPackage,或不使用它)或调用其他方法(如查询),它&#39 ;好的。导致情况发生的原因,任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

只需在application.yml中添加以下代码:

ribbon:
  # Max number of retries on the same server (excluding the first try)
  MaxAutoRetries: 0
  # Max number of next servers to retry (excluding the first server)
  MaxAutoRetriesNextServer: 0