zoukankan      html  css  js  c++  java
  • apache cxf之 一个简单的JAX-WS服务程序

    推荐一本apache cxf的书籍:

    apache cxf的配置,这边就不做介绍了。请参照我关于它配置的博文。

    开发步骤:

    1、新建Java project,build path引入cxf runtime。

    2、新建SEI服务接口:

    package demo.cxf.helloworld;
    
    import javax.jws.WebParam;
    
    public interface HelloWorld {
    	public String sayHello(@WebParam(name="text")String text);//注解定义web参数的
    }
    


    3、服务的实现:

    package demo.cxf.helloworld;
    
    import javax.jws.WebParam;
    import javax.jws.WebService;
    
    @WebService(name="HelloWorld")//注解定义服务
    public class HelloWorldImpl implements HelloWorld {
    
    	@Override
    	public String sayHello(@WebParam(name="text")String text) {
    		System.out.println("sayHello called");
    		return "Hello "+text+",this is world!";
    	}
    
    }
    


    4、服务的发布与测试

    package demo.cxf.helloworld.server;
    
    import java.io.IOException;
    
    import javax.xml.ws.Endpoint;
    
    import demo.cxf.helloworld.HelloWorld;
    import demo.cxf.helloworld.HelloWorldImpl;
    
    public class Server {
    
    	public static void main(String[] args) throws IOException {
    		Server server = new Server();
    		server.startServer();
    		System.out.println("Startting ready...");
    		System.in.read();//按任意键退出
    		System.out.println("Server exiting...");
    		System.exit(0);//程序退出
    	}
    	
    	public void startServer(){
    		System.out.println("Starting Server.....");
    		HelloWorld helloWorld = new HelloWorldImpl();
    		String address = "http://localhost:8080/HelloWorld";
    		
    		//发布服务
    		Endpoint.publish(address, helloWorld);
    	}
    
    }
    


    测试:run as java application

    浏览器访问:http://localhost:8080/HelloWorld?wsdl


  • 相关阅读:
    CF1284G
    5-3 Harbor高可用部署 下
    5业务系统迁移kubernetes-----准备工作(平稳迁移做好准备)
    题解-CF1453F Even Harder
    题解-CF961F k-substrings
    Docker 数据卷容器(实现两个或多个容器间数据同步)
    Docker 具名和匿名挂载
    Java-IO中的节点流和处理流
    《机器学习十讲》学习报告二
    rpc基本思路
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3181476.html
Copyright © 2011-2022 走看看