地址: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("廣州");