cxf JaxWsClientFactoryBean

JaxWsClientFactoryBean是CXF中用于简化创建JAX-WS客户端端点的Bean。它涉及设置WsdlURL、地址、服务类和Bus等属性。JAX-WS是一种将远程调用转化为基于XML(如SOAP)协议的方法。create方法用于生成客户端,而setThreadLocalRequestContext允许配置请求上下文是全局还是线程局部。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   在项目中看到,不知道干啥用,好像是2.7版本的新方法的在网上搜没有找到相关信息,查看了cxf api 才明白

    api url  http://cxf.apache.org/javadoc/latest/

       备注 :Bean to help easily create Client endpoints for JAX-WS. 大概意思帮助bean简单的创建客户端连接点JAX- WS.

         何为JAX-WS. 大概意思是一个远程调用可以转换为一个基于XML的协议,java也就是我们soap协议

           方法介绍

          setWsdlURL:来自于cxf JaxWsClientFactoryBean父类的父类AbstractWSDLBasedEndpointFactory

                                 字面意思用于获取wsdlUrl也就是soap协议

                               public void setWsdlURL(String wsdlURL) {//用嵌套类方法给ReflectionServiceFactoryBean封装类传值
                                            getServiceFactory().setWsdlURL(wsdlURL);
                                      }

           setAddress:

                          public void setAddress(String address) {
                                 this.address = address;
                            }

         setServiceClass:传入了生成客户端代码中的映射字段的接口。

                     public void setServiceClass(Class<?> serviceClass) {
                             super.setServiceClass(serviceClass);

                             (super代码  this.serviceClass = serviceClass; )
                           if (((JaxWsServiceFactoryBean)getServiceFactory()).getJaxWsImplementorInfo() == null) {

               //判断传入的wsdlURl是否为空  如果为空的情况下要根据serviceClass给wsdlurl赋值
                             JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(serviceClass);
                            ((JaxWsServiceFactoryBean)getServiceFactory()).setJaxWsImplementorInfo(implInfo);
                         }
                       }

     setBus     :传入的是一个bus类型数据,

                       例如:

                        SpringBusFactory bf = new SpringBusFactory();
                         bus = bf.createBus();
                        SpringBusFactory.setDefaultBus(bus);
                        SpringBusFactory.setThreadDefaultBus(bus);
                        jwpf.setBus(bus);

                        public void setBus(Bus bus) {
                              this.bus = bus;
                       }

       create :根据名字理解创建客户端

                    public Client create() {
                   getServiceFactory().reset();  //设定了 dataBinding=null  dataBindingSet为false
        if (getServiceFactory().getProperties() == null) {
            getServiceFactory().setProperties(properties);
        } else if (properties != null) {
            getServiceFactory().getProperties().putAll(properties);
        }
        Client client = null;
        Endpoint ep = null;
        try {
            ep = createEndpoint();
            this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_CLIENT_CREATE, ep);
            applyProperties(ep);
            client = createClient(ep);
            initializeAnnotationInterceptors(ep, getServiceClass());
        } catch (EndpointException e) {
            throw new ServiceConstructionException(e);
        } catch (BusException e) {
            throw new ServiceConstructionException(e);
        }
        applyFeatures(client);
        this.getServiceFactory().sendEvent(FactoryBeanListener.Event.CLIENT_CREATED, client, ep);
        return client;
    }

   获取了client 还该怎么做呢如下

      client.setThreadLocalRequestContext(true);下面是注解的翻译

      设置请求上下文是线程本地的还是全局的。默认情况下,请求上下文是“全局”的,在上下文中设置的任何值都可以通过使用此客户端的所有线程看到。如果设置为true,背景改为一个ThreadLocal和设置的值不被其他线程看到。

     

          

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值