package cn.itcast.cxf; import javax.jws.WebService; @WebService
public interface IHelloService {
public String sayHello(String name);
}
package cn.itcast.cxf; import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean; public class HelloServiceImpl implements IHelloService { @Override
public String sayHello(String name) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(new Date())+ " ---hello " + name;
}
public static void main(String[] args) {
JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
bean.setAddress("http://192.168.1.112:7788/hello");
bean.setServiceClass(IHelloService.class);//接口类型
bean.setServiceBean(new HelloServiceImpl());
//加入请求消息拦截器
bean.getInInterceptors().add(new LoggingInInterceptor());
//加入响应消息拦截器
bean.getOutInterceptors().add(new LoggingOutInterceptor());
bean.create();
System.out.println("server ready...");
} }