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...");
           }
    }
  • 相关阅读:
    MyBatis与Spring的整合
    Spring核心AOP(面向切面编程)
    Spring核心IoC(控制反转)
    动态SQL
    SQL映射文件
    初识MyBatis
    注解和反射
    Linux配置SVN和MemCached
    Java Web Day10
    Java Web Day9
  • 原文地址:https://www.cnblogs.com/ZHONGZHENHUA/p/7669857.html
Copyright © 2011-2022 走看看