java cxf 客户端_[cxf]CXF客户端配置文件之包含文件

主旨:

在CXF服务端配置WEB SERVICE时,通常会包含一些来此cxf.jar里面的XML文件,用于自动配置需要使用到的BEAN

例如:

1

4f1150b881333f12a311ae9ef34da474.png24f1150b881333f12a311ae9ef34da474.png34f1150b881333f12a311ae9ef34da474.png

但是在客户端配置的时候这些文件是不需要的,甚至配置会引发错误,详细的经过见下文。

经过:

今天在配置客户端的时候,步骤和内容都是和往常一样的,但是

出现一个NullPointerException 的错误,只知道这个错误是在创建客户端service的时候出的错,但是原因找不到。

错误堆栈:

4f1150b881333f12a311ae9ef34da474.pngCaused by: java.lang.NullPointerException    

4f1150b881333f12a311ae9ef34da474.png    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpointInfo(AbstractWSDLBasedEndpointFactory.java:160)    

4f1150b881333f12a311ae9ef34da474.png    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:102)    

4f1150b881333f12a311ae9ef34da474.png    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:51)    

4f1150b881333f12a311ae9ef34da474.png    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:97)    

4f1150b881333f12a311ae9ef34da474.png    at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:89)    

4f1150b881333f12a311ae9ef34da474.png    at com.itravel.cxf.client.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:25)    

4f1150b881333f12a311ae9ef34da474.png    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    

4f1150b881333f12a311ae9ef34da474.png    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)    

4f1150b881333f12a311ae9ef34da474.png    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    

4f1150b881333f12a311ae9ef34da474.png    at java.lang.reflect.Method.invoke(Method.java:585)    

4f1150b881333f12a311ae9ef34da474.png    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)   

4f1150b881333f12a311ae9ef34da474.png

直到后来我单独加载了创建客户端service的applicationContext时,初始化是正常的,所以就怀疑配置文件出了问题;

当上面提到的几个被包含进来的文件的配置被删除后,一切就正常了。

Let life be beautiful like summer flowers and death like autumn leaves.

posted on 2009-02-18 15:03 Alexwan 阅读(4941) 评论(1)  编辑  收藏 所属分类: J2EE 、小笔记

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!关于使用Spring Boot和Apache CXF开发客户端的问题,我可以为您提供一些指导。 首先,您需要在您的Spring Boot项目中添加CXF的依赖。可以在您的pom.xml文件中添加以下依赖: ```xml <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.4.1</version> </dependency> ``` 接下来,您可以创建一个CXF客户端来调用远程WebService。您可以使用`@WebServiceClient`注解来生成客户端代码。例如,假设您要调用一个名为"HelloWorldService"的WebService: ```java @WebServiceClient(name = "HelloWorldService", targetNamespace = "http://example.com/", wsdlLocation = "http://example.com/HelloWorldService?wsdl") public class HelloWorldServiceClient extends Service { public HelloWorldServiceClient(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } public HelloWorldService getHelloWorldServicePort() { return super.getPort(HelloWorldService.class); } } ``` 在上面的代码中,`wsdlLocation`参数指定了远程WebService的WSDL地址。`getHelloWorldServicePort()`方法返回了一个用于调用WebService方法的接口。 接下来,您可以在您的Spring Boot应用程序中使用这个客户端。您可以将它注入到您的服务或控制器中,并使用它来调用远程WebService方法。例如: ```java @Service public class MyService { @Autowired private HelloWorldServiceClient helloWorldServiceClient; public void invokeRemoteService() { HelloWorldService helloWorldService = helloWorldServiceClient.getHelloWorldServicePort(); String result = helloWorldService.sayHello("World"); System.out.println(result); } } ``` 在上面的代码中,通过`helloWorldServiceClient.getHelloWorldServicePort()`方法获取到了远程WebService的接口实例,然后可以调用其中的方法。 这就是使用Spring Boot和CXF开发客户端的基本步骤。您可以根据您的具体需求进一步进行配置和调整。希望对您有所帮助!如果您有更多问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值