CXF 端点定义,并且无法在注册表中找到解析 endpoint:No bean

CXF endpoint definition, and Failed to resolve endpoint:No bean could be found in the registry

我尝试定义一个 CXF 端点,但它不起作用。 当我想解决端点时,我得到了 "bean not found" 异常。

CXF 定义:

    @Override
    public void configure() throws Exception
    {

        errorHandler(deadLetterChannel(systemInfo.getQueuName())
                .allowRedeliveryWhileStopping(true)
                .maximumRedeliveries(-1)
                );

        onException(Exception.class).process(routeHandlingBean);


        CamelContext camelContext = getContext();

        CxfEndpoint partnerTestService = new CxfEndpoint();
        partnerTestService.setEndpointNameString("partnerTestService");
        partnerTestService.setAddress("http://localhost:9081/MockPartnerService");
        partnerTestService.setWsdlURL("http://localhost:9081/MockPartnerService?wsdl");
        partnerTestService.setServiceClass(aaa.bbb.ccc.service.PartnerService.class);
        partnerTestService.setServiceNameString("partnerTestService");
        partnerTestService.setDataFormat(DataFormat.CXF_MESSAGE);
        partnerTestService.setCamelContext(camelContext);

        try {
            camelContext.addEndpoint("partnerTestService", partnerTestService);
        } catch (Exception e) {
            e.printStackTrace();
        }

当我尝试调用端点时:

cxf:bean:partnerTestService

然后我收到这个错误信息:

org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: cxf://bean:partnerTestService due to: No bean could be found in the registry for: partnerTestService of type: org.apache.camel.component.cxf.CxfEndpoint

我不知道我还需要设置什么。

谢谢! 费里

解决方案是使用 CxfEndpoint class。我写了一个返回所需对象(而不是字符串端点)的函数,所以它可以工作。

路由定义:

    ValueBuilder dynRouterMethod = method(esbDynRouter, "endpointRoute");

    from(queueName).id(systemInfo.getRouteId()).routeId(systemInfo.getRouteId()).autoStartup(false)
    .transacted()
    .log(LoggingLevel.INFO, systemInfo.getRouteId() + " route usage.")
    .beanRef("statusUpdaterBean", "updateSendingStatus")
    .dynamicRouter(dynRouterMethod)
    .beanRef("statusUpdaterBean", "updateSentStatus")
    ;

程序(在动态路由器程序中调用):

private CxfEndpoint getCxfEndpoint(DispConfView target) throws Exception
    {
        CxfEndpoint cxfEndpoint = (CxfEndpoint) camelContext.getEndpoint(<Something>);

        if (cxfEndpoint == null)
        {
            String serviceClassNme = <class name what represent the POJO class>;
            String methodName = <WS methode name>;

            cxfEndpoint = new CxfEndpoint();
            cxfEndpoint.setAddress(methodName);
            cxfEndpoint.setDataFormat(DataFormat.POJO);
            cxfEndpoint.setServiceClass(serviceClassNme);

            cxfEndpoint.setCamelContext(camelContext);

            camelContext.addEndpoint(<Something>, cxfEndpoint);
        }

        return cxfEndpoint;
    }

如果消息是 POJO 类型,则此解决方案有效。