CXF客户端启动过程

本文通过一个简单的示例介绍了如何使用CXF框架结合JAX-WS规范实现服务的发布与调用。从客户端和服务端两方面详细展示了代码实现过程,并分析了配置文件加载机制。

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

最近,在研究CXF,在用JaxWsProxyFactoryBean 完成调用服务端虽然成功,但是不明白道理,所以DEBUG+源代码了哈

客户端代码:
public final class Client {

private Client() {
}

public static void main(String args[]) throws Exception {
JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.setServiceClass(demo.spring.HelloWorld.class);
factoryBean.setAddress("http://localhost:8080/HelloWorld");

HelloWorld client = (HelloWorld) factoryBean.create();

String response = client.sayHi("Joe");
System.out.println("Response: " + response);
System.exit(0);

}
}
服务器端代码:CXF包的SAMPLE,我们要看的是客户端代码:
这个DEMO非常简单!
package demo.spring;

import javax.jws.WebService;

@WebService
public interface HelloWorld {
String sayHi(String text);
}

package demo.spring;

import javax.jws.WebService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
private final static Log log = LogFactory.getLog(HelloWorldImpl.class);

public String sayHi(String text) {
log.info("@WebService Hello support service");
return "Hello " + text;
}
}
bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: beans -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint id="helloWorld"
implementor="demo.spring.HelloWorldImpl" address="/HelloWorld" />

</beans>
<!-- END SNIPPET: beans -->

分析:
   在把服务器端DEPLOY到TOMCAT然后启动
   运行客户端,发现SPRING LOAD很多XCF.JAR下面的META-INF下的XML文件,怎么LOAD,一定那里有配置或者约定!

   结果果然是:
         JaxWsProxyFactoryBean.java
         ClientProxyFactoryBean.java
         ClientFactoryBean.java
         AbstractWSDLBasedEndpointFactory.java
         AbstractEndpointFactory.java
         BusFactory.java
         SpringBusFactory.java
         BusApplicationContext.java[哈哈上下文....]
BusFactory.java 内部去找JAR包下面的配置文件了哈找到SpringBusFactory
String serviceId = "META-INF/services/" + BusFactory.BUS_FACTORY_PROPERTY_NAME;

SpringBusFactory 搞定BusApplicationContext
BusApplicationContext内部
private static final String DEFAULT_CXF_CFG_FILE = "META-INF/cxf/cxf.xml";
private static final String DEFAULT_CXF_EXT_CFG_FILE = "classpath*:META-INF/cxf/cxf.extension";
一切就搞定
附件有代码:和PPT[截图]

希望大家分享,CXF资料不多哈
努力!!
         
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值