地址:http://cxf.apache.org/download.html 选择适合自己的版本
CXF_HOME = C:\tomcat\apache-cxf-3.3.4
1、创建一个普通的Java项目,导入如图的jar包,将该目录下的jar都导入到项目中
public interface WeatherInterface
public String getWeather(String city);
public String[] getCities(String pro);
public class WeatherInterfaceImpl implements WeatherInterface {
public String getWeather(String city) {
public String[] getCities(String pro) {
return new String[]{"广州" , "深圳" , "佛山"};
return new String[]{"该省暂未开通"};
4、发布服务,在main方法写入如下代码,然后执行main方法
import my.WeatherInterfaceImpl;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public static void main(String[] args) {
JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
factoryBean.setServiceBean(new WeatherInterfaceImpl());
factoryBean.setAddress("http://127.0.0.1:9090/weather");
在浏览器地址栏打开地址:http://127.0.0.1:9090/weather?wsdl
(2)在dows窗口执行;wsdl2java -d . http://127.0.0.1:9090/weather?wsdl
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
public static void main(String[] args)
System.out.println("hello world!");
JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
factoryBean.setServiceClass(WeatherInterface.class);
factoryBean.setAddress("http://127.0.0.1:9090/weather?wsdl");
WeatherInterface ws = factoryBean.create(WeatherInterface.class);
String str = ws.getWeather("广州");
List<String> citis = ws.getCities("广东");
到此,cxf发布webservice已经做好了。