【Java通过Cxf创建webService接口】
一、导入cxf需要的jar包
二、编写服务类
public class CxfService implements CxfServiceImpl {
/* (non-Javadoc)
* @see cn.com.liveuc.cxf.service.CxfServiceImpl#getSay(java.lang.String)
*/
@WebMethod
public String getSay(String name) {
return “say:” + name + “时间:” + new Date();
}
}
@WebService
public class CxfService implements CxfServiceImpl {
/* (non-Javadoc)
* @see cn.com.liveuc.cxf.service.CxfServiceImpl#getSay(java.lang.String)
*/
@WebMethod
public String getSay(String name) {
return “say:” + name + “时间:” + new Date();
}
}
三、抽取接口
public interface CxfServiceImpl {
@WebMethod
public abstract String getSay(String name);
}
@WebService
public interface CxfServiceImpl {
@WebMethod
public abstract String getSay(String name);
}
四、写启动类
public class StartService {
public StartService() {
//实例化服务类
CxfService cs = new CxfService();
//用ServerFactoryBean发布服务
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
//设置服务访问地址
sf.setAddress(“http://127.0.0.1:9090/say”);
//设置服务接口类
sf.setServiceClass(CxfServiceImpl.class);
//设置服务具体类
sf.setServiceBean(cs);
//开启服务
sf.create();
}
public static void main(String[] args) {
new StartService();
}
}
更多精彩教程请关注:大白菜官网u盘装系统