• 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...");
           }
    }
  • 相关阅读:
    面试题3(百思教育面试软件开发岗位笔试题)
    python开发工具安装
    涉及 委托事件 程序运行越来越慢
    整理收藏
    数据库作业创建
    剑指offer-面试题37:序列化二叉树及二叉树的基本操作和测试
    剑指offer-面试题41:数据流中的中位数
    快速排序及其优化
    冒泡排序算法及相应的优化
    leetcode问题:缺失数字
  • 原文地址:https://www.cnblogs.com/ZHONGZHENHUA/p/7669857.html
Copyright © 2020-2023  润新知