首页 > Web开发 > 详细

项目一:第六天 WebService写接口 和CXF框架

时间:2018-06-22 00:46:43      阅读:388      评论:0      收藏:0      [点我收藏+]

课程计划

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  生成代码

 

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

 技术分享图片

 

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

 

技术分享图片

 

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

 技术分享图片

项目一:第六天 WebService写接口 和CXF框架

原文:https://www.cnblogs.com/shan1393/p/9211339.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!