随着SOA架构在企业级生活的越来越流行,具体使用SOA能力是程序员不可或缺的能力。下面简单介绍发布一个简单CXF服务的步骤。
1、开发一个业务服务接口,并在接口上写上注解@WebService
package com.skydream.cxf;
import javax.jws.WebService;
@WebService
public interface IHelloService{
String sayHello(String name);
}
说明:Webservice注解是JDK提供的,具体使用可查JDK文档。
2、开发一个实现类,同样写上注解@Webservice(endpointInterface="",serviceName="")
package com.skydream.cxf.impl;
import java.util.Date;
import javax.jws.WebService;
import com.skydream.cxf.IHelloService;
@WebService(endpointInterface="com.skydream.cxf.IHelloService",serviceName="helloService")
public class HelloServiceImpl implements IHelloService
{
@Override
public String sayHello(String name)
{
// TODO Auto-generated method stub
return "Hello "+name+" ;Now time is "+new Date();
}
}
3、发布服务
IHelloService objIHelloService = new HelloServiceImpl();
CxfPublish objCxfPublish = new CxfPublish();
objCxfPublish.publishCxf("http://127.0.0.1/helloService", objIHelloService);
System.out.println("publish success!");
说明:发布需要依赖CXF及相关 jar.
本发布使用到了jetty 内置web服务器
4、验证
访问http://127.0.0.1/helloService,看到WSDL文件说明成功。
ok!