zoukankan      html  css  js  c++  java
  • cxf3.x +spring 3.x(4.x)+ maven 发布webservice 服务

    cxf 在做企业级webservices 服务的时候确实非常好用,个人觉得比axis1, 2都好用。
    虽然spring自身也提供了webservices发布方法,这里使用cxf跟spring结合,使用起来非常方便;


    整体项目结果如下:

    整体结构

    基于maven 来配置使得项目更加简单

    1. 新建一个maven 项目,补全 src下的main和test目录

    2. 打开web.xml

    <?xml version="1.0" encoding="UTF-8"?> 
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>cxf</display-name> 
    <servlet> 
    <description>m CXF Endpoint</description> 
    <display-name>cxf</display-name> 
    <servlet-name>cxf</servlet-name> 
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>cxf</servlet-name> 
    <url-pattern>/services/*</url-pattern> 
    </servlet-mapping> 
    <session-config> 
    <session-timeout>60</session-timeout> 
    </session-config> 
    </web-app>
    
    1. 新建一个cxf-servlet.xml
    <?xml version="1.0" encoding="UTF-8"?> 
    <!-- START SNIPPET: beans --> 
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xsi:schemaLocation=" http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> 
    <import resource="classpath:META-INF/cxf/cxf.xml"/> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> 
    <jaxws:endpoint id="DepartmentService" implementor="com.qycloud.oatos.ty.department.DepartmentServiceImpl" address="/DepartmentService"/> 
    <jaxws:endpoint id="UserService" implementor="com.qycloud.oatos.ty.user.UserServiceImpl" address="/UserService"/> 
    </beans>
    
    1. 补全 pom.xml ,主要是spring 的依赖和cxf,cxf 只需要以下2个
    <dependency> 
    <groupId>org.apache.cxf</groupId> 
    <artifactId>cxf-rt-frontend-jaxws</artifactId> 
    <version>3.0.0</version> 
    </dependency> 
    <dependency> 
    <groupId>org.apache.cxf</groupId> 
    <artifactId>cxf-rt-transports-http</artifactId> 
    <version>3.0.0</version> 
    </dependency>
    
    1. 编写代码:这里我们回头看到cxf-servlet.xml 里面可发现我们只需要制定一个id,一个是实现类,一个访问地址即可。

    a) 编写一个接口

    @WebService 
    public interface DepartmentService { 
    
    boolean updateTheOrg(String org); 
    
    boolean updateOrgsCode(String org); 
    
    }
    

    b) 编写一个实现类

    @WebService(endpointInterface = "com.qycloud.oatos.ty.department.DepartmentService") 
    public class DepartmentServiceImpl implements DepartmentService { 
    
    @Override 
    public boolean updateTheOrg(String org) { 
    // TODO Auto-generated method stub 
    return false; 
    } 
    
    @Override 
    public boolean updateOrgsCode(String org) { 
    // TODO Auto-generated method stub 
    return false; 
    } 
    
    }
    

    7.剩下的事情就是发布了。右键run on server。结果如下

    效果

    1. demo下载地址
    自吹自擂的互联网
  • 相关阅读:
    论文笔记之:Speed Up Tracking by Ignoring Features
    深度学习中常见的几个基础概念
    (转)The AlphaGo Replication Wiki
    论文笔记之:Co-saliency Detection via A Self-paced Multiple-instance Learning Framework
    (转)CVPR 2016 Visual Tracking Paper Review
    论文笔记之:Generative Adversarial Text to Image Synthesis
    论文笔记之:Conditional Generative Adversarial Nets
    论文笔记之:Progressive Neural Network Google DeepMind
    (转)Let’s make a DQN 系列
    论文阅读之:Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network
  • 原文地址:https://www.cnblogs.com/jiuyuehe/p/3845362.html
Copyright © 2011-2022 走看看