首页 > 代码库 > cxf利用接口规范写法发布webservice

cxf利用接口规范写法发布webservice

 

1 package cn.itcast.cxf;2 3 import javax.jws.WebService;4 5 @WebService6 public interface IHelloService {7     public String sayHello(String name);8 }

 

 1 package cn.itcast.cxf; 2  3 import java.text.SimpleDateFormat; 4 import java.util.Date; 5  6  7 import org.apache.cxf.interceptor.LoggingInInterceptor; 8 import org.apache.cxf.interceptor.LoggingOutInterceptor; 9 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;10 11 12 public class HelloServiceImpl implements IHelloService {13 14     @Override15     public String sayHello(String name) {16         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");17         return sdf.format(new Date())+ " ---hello " + name;18     }19     public static void main(String[] args) {20         JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();21         bean.setAddress("http://192.168.1.112:7788/hello");22         bean.setServiceClass(IHelloService.class);//接口类型23         bean.setServiceBean(new HelloServiceImpl());24         //加入请求消息拦截器25         bean.getInInterceptors().add(new LoggingInInterceptor());26         //加入响应消息拦截器27         bean.getOutInterceptors().add(new LoggingOutInterceptor());28         bean.create();29         System.out.println("server ready...");30     }31 32 }