zoukankan      html  css  js  c++  java
  • 项目一:第六天 WebService写接口 和CXF框架

    课程计划

    1、 webService入门(了解)

    2、 基于jdk1.7开发webservice服务(了解)

    3、 Apache CXF框架入门(掌握)

    4、 基于CXF框架搭建CRM系统(掌握)

     

     

     

    1.1 wsdl  webservice描述/定义语言

     

    俗称web服务使用说明书

     

     

     

     

     

    网络服务描述/定义语言:每一个webservice服务都有自己wsdl

     

    wsdl是标准xml文件,wsdlxml文件)包含服务名称,服务中包含方法名方法参数(参数类型),方法返回类型

     

     

     

    通过jdk提供命令wsimport,解析wsdl(本质就是xml文件),生成客户端java调用代码(生成代码方法名称,方法参数,方法返回类型)

     

     

     

    WSDL地址:服务地址+WSDL

     SOAP =html+xml;

     SOAP :简单对象访问协议,规定了WebService远程调用传输的xml数据格式.

     

     CXF一个小demo

    通过spring工厂产生代理对象;

    1、 创建新的工程

    2、 cxf的相关jar包到入项目

    3、 提供cxf配置文件:spring配置文件

    4、 只需要拷贝生成的服务接口到项目中,在cxf配置文件中进行配置

     

     

    基于cxf搭建CRM项目环境

     

    CRM系统只是为了提供webservice服务供其他两个项目:后台管理系统,前台系统调用;没有提供客户数据维护页面;

     

    CRM项目中使用技术:spring+spring-data-jpa +CXF +oracle数据库

     

    1、 创建maven project  父工程为:common_parent

     

     

    1.1.1 CRM框架环境

    Spring+spring-data-jpa+CXF

     

    1、 搭建spring环境

    a) 配置文件:applicationContext.xml

    b) Web.xml配置监听器

    2、 Spring整合jpa

    3、 Spring-data-jpa  :2,3配置去复制bos_web项目下  注意:包扫描路径改为crm

     

     

    ?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

    xmlns:aop="http://www.springframework.org/schema/aop"

    xmlns:context="http://www.springframework.org/schema/context"

    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 

    xmlns:jaxws="http://cxf.apache.org/jaxws"

    xmlns:soap="http://cxf.apache.org/bindings/soap"

    xmlns:tx="http://www.springframework.org/schema/tx"

    xmlns:jpa="http://www.springframework.org/schema/data/jpa" 

    xmlns:task="http://www.springframework.org/schema/task"

    xsi:schemaLocation="

    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd

    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd

    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd

    http://www.springframework.org/schema/data/jpa

    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd

    http://cxf.apache.org/bindings/soap

    http://cxf.apache.org/schemas/configuration/soap.xsd

    http://cxf.apache.org/jaxws

    http://cxf.apache.org/schemas/jaxws.xsd">

    1、 服务端CXF环境

    a) Web.xml配置servlet

    <!-- 配置cxfServlet 处理客户端请求 -->

      

      <servlet>

       <servlet-name>cxf</servlet-name>

       <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

    <!--    <init-param>之前通过初始化参数加载spring配置文件,发布服务;现在已经配置监听器</init-param> -->

      </servlet>

      

      <servlet-mapping>

       <servlet-name>cxf</servlet-name>

    <url-pattern>/service/*</url-pattern>  

      </servlet-mapping>

    5Web.xml

    <!-- spring的监听器 -->

    <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

     

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath:applicationContext.xml</param-value>

    </context-param>

     

    <!-- cxfServlet:处理客户端请求  2、发布服务 -->

    <servlet>

    <servlet-name>cxf</servlet-name>

    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

    </servlet>

     

    <servlet-mapping>

    <servlet-name>cxf</servlet-name>

    <url-pattern>/service/*</url-pattern>

    </servlet-mapping>

    Web.xml

    <!-- spring的监听器 -->

    <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

     

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath:applicationContext.xml</param-value>

    </context-param>

     

    <!-- cxfServlet:处理客户端请求  2、发布服务 -->

    <servlet>

    <servlet-name>cxf</servlet-name>

    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

    </servlet>

     

    <servlet-mapping>

    <servlet-name>cxf</servlet-name>

    <url-pattern>/service/*</url-pattern>

    </servlet-mapping>

     

     

    1.1 实现案例

    1、 创建服务接口,在接口上使用注解@WebService,创建实现类

     

     

    2、 Cxf配置文件中,配置webservice服务端对象

     

    3、 启动项目:查询webservice服务

    Wsdl地址:服务地址+wsdl

    1、 完善服务端查询所有客户方法

    a) 创建dao继承jparepository

    b) dao对象注入service

     

     

     

    1.1 bos调用服务户端CRM方法

    1、 获取wsdl地址:http://localhost:8082/bos_crm/service/customer?wsdl  生成代码 通过jdk命令 wsimport

     

    2、 将接口拷贝到bos-service项目中

     

    1、 在客户端spring配置文件中,配置客户端调用对象

     

    1、 在需要调用CRM的代码中注入客户端对象

     

  • 相关阅读:
    经典SQL语句大全
    《构建高性能Web站点》观后感
    网搜索引擎架构设计
    使用Windows系统的几个好的习惯
    静态页面对seo优化之详解
    让您SEO学习时间缩短一半的高阶秘籍
    java链表
    GAE 数据存储——事务
    GAE 博客——B3log Solo 0.2.0 发布了!
    Wine 1.3.7 发布
  • 原文地址:https://www.cnblogs.com/shan1393/p/9211339.html
Copyright © 2011-2022 走看看