10.通过CXF的wsdl2java命令生成客户端调用代码讲解

 

import com.gyf.weather.WeatherInterface;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import java.util.List;

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello World!");

        //使用CXF方式调用
        //1.创建式bean
        JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();

        //2.设置接口
        factoryBean.setServiceClass(WeatherInterface.class);

        //3.设置的地址
        factoryBean.setAddress("http://127.0.0.1:12345/weather?wsdl");

        //4.创建服务
        WeatherInterface ws = factoryBean.create(WeatherInterface.class);

        List<String > cities = ws.getCityNameByProvince("广西");

        System.out.println(ws.queryWeather("广州"));
        System.out.println(cities);
    }
}

 

posted @ 2019-05-01 13:12  expworld  阅读(232)  评论(0)    收藏  举报