zoukankan      html  css  js  c++  java
  • day63-webservice 05.发布接口实现类的webservice

    package com.rl.cxf.client;
    
    import com.rl.inter.HI;
    import com.rl.inter.HIService;
    
    public class HiInterClient {
        public static void main(String[] args) {
            
        
        HIService hiService = new HIService();
        //返回的服务的实现类使用接口接收
        HI hi = hiService.getHIPort();
        
        String result  = hi.sayHi("王五");
        System.out.println(result);
        
        }
    }
    package com.rl.cxf.inter;
    
    import javax.jws.WebService;
    
    @WebService
    public interface HI {
       
       public String sayHi(String name);
    }
    package com.rl.cxf.inter;
    
    public class HIImpl implements HI{
    
        @Override
        public String sayHi(String name) {
            // TODO Auto-generated method stub
            return name+ " hi";
        }
       
    }
    package com.rl.cxf.server;
    
    import org.apache.cxf.interceptor.LoggingInInterceptor;
    import org.apache.cxf.interceptor.LoggingOutInterceptor;
    import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
    
    import com.rl.cxf.inter.HI;
    import com.rl.cxf.inter.HIImpl;
    
    public class MyCXFServerInter {
        public static void main(String[] args) {
             //创建服务工厂对象
             //ServerFactoryBean sfb = new ServerFactoryBean();
             JaxWsServerFactoryBean sfb = new JaxWsServerFactoryBean();
             //加入输入输出拦截器
             sfb.getInInterceptors().add(new LoggingInInterceptor());
             //sfb.getOutFaultInterceptors().add(new LoggingOutInterceptor());
             sfb.getOutInterceptors().add(new LoggingOutInterceptor());
             //指定服务地址
             sfb.setAddress("http://127.0.0.1:9999/hi");
             //设置接口
             sfb.setServiceClass(HI.class);
             //设置接口实现类
             sfb.setServiceBean(new HIImpl());
             //发布服务
             sfb.create();
             System.out.println("server ready...");
           }
    }
  • 相关阅读:
    MySQL时间函数
    Linux安装php运行环境
    linux 防火墙配置
    CENTOS启动后网卡启动不了
    价值
    浏览器STATUS_INVALID_IMAGE_HASH报错解决方法
    wordpress更改域名最简单的方法
    Connection to 天mysql failed. [08001] Could not create connection to database server. Attempted ,报错处理方法
    centos实现三个节点高可用
    安装nginx1.16.1版本
  • 原文地址:https://www.cnblogs.com/ZHONGZHENHUA/p/7669857.html
Copyright © 2011-2022 走看看