---
title: "第一次 cxf"
author: "lmning"
date: "2009-04-16T15:23:01Z"
tags: []
slug: "cxf"
draft: false
lastmod: "2009-04-16T15:23:01Z"
id: 368787
url: "https://lmning.iteye.com/blog/368787"
---

```
 
```

```
 
```

```
到apache 下载cxf需要的包，最好jdk6.0免得出错
```

```
public class WebserviceServer {

	public WebserviceServer(){
		HelloServiceImpl hello = new HelloServiceImpl();
		ServerFactoryBean factory = new ServerFactoryBean();
		factory.setServiceClass(IHelloService.class);
		factory.setAddress("http://127.0.0.1:9000/Hello");
		factory.setServiceBean(hello);
		factory.create();
	}
	public static void main(String[] args) throws InterruptedException {
		new WebserviceServer();
		System.out.println("server starting......");
		Thread.sleep(60*1000);
		System.out.println("server exit");
		System.exit(0);
		
	}
```

 

 

启动server

 

浏览器查看：

[http://127.0.0.1:9000/Hello?WSDL](http://127.0.0.1:9000/Hello?WSDL)

 

调用webservice

 

```
public class Client {

	
	public static void main(String[] args) {
		ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
		factory.setServiceClass(IHelloService.class);
		factory.setAddress("http://127.0.0.1:9000/Hello");
		IHelloService hello = (IHelloService) factory.create();
		System.out.println(hello.sayHello("hello lmning"));

	}

}
```

  

 

ok！