package CXF01;
import java.util.Date;
import javax.jws.WebService;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import org.springframework.context.annotation.Bean;
import webservice.HelloService;
/**
* 使用ServerFactoryBean发布WebService项目
* @author Dqd
*
*/
@WebService
public class HelloServer {
public String sayHello(String name){
System.out.println("sayHello called。。");
return new Date()+"hello"+name;
}
public static void main(String[] args) {
/*//创建一个服务工厂对象
ServerFactoryBean sfb = new ServerFactoryBean();
//设置发送地址
sfb.setAddress("http://127.0.0.1:8080/hellow");
//设置提供服务接口,没有接口为本类
sfb.setServiceClass(HelloService.class);
//设置提供服务的实例
sfb.setServiceBean(new HelloServer());
//发布服务
sfb.create();
System.out.println("Server Ready。。。。。。。");*/
JaxWsServerFactoryBean bean = new
JaxWsServerFactoryBean();
bean.setAddress("http://127.0.0.1:8081/hi");
bean.setServiceClass(HelloServer.class);
bean.setServiceBean(new HelloServer());
//客户端请求消息拦截器
bean.getInInterceptors().add(new LoggingInInterceptor());
//客户端相应消息拦截器
bean.getInInterceptors().add(new LoggingOutInterceptor());
bean.create();
System.out.println("Server Ready。。。。。。。");
}
}
java项目WebService项目的发布和访问
最新推荐文章于 2024-06-07 11:53:06 发布