• 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下载地址
    自吹自擂的互联网
  • 相关阅读:
    fail to start File System Check
    qemu:///system 没有连接驱动器可用;读取数据时进入文件终点: 输入/输出错误
    [转载]libvirt(virsh命令总结)
    【转载】CentOS 7自动以root身份登录gnome桌面 操作系统开机后自动登录到桌面 跳过GDM
    Linux查看PCIe版本及速率# lspci -vvv |grep Width -i
    JAVA的线程能够在多个CPU上执行么?
    给定字典做分词
    POJ 3130 &amp; ZOJ 2820 How I Mathematician Wonder What You Are!(半平面相交 多边形是否有核)
    高仿一元云购IOS应用源代码项目
    增加收藏兼容主流浏览器代码
  • 原文地址:https://www.cnblogs.com/jiuyuehe/p/3845362.html
Copyright © 2020-2023  润新知