该项目在上文   WebService学习总结(四)--基于CXF的服务端开发  的基础上修改为spring上发布的webservice接口

1、新建web project 工程

2、导入spring和cxf的有关jar包

3、 在src 目录下,配置sping 的配置文件

4、在src 目录,新建一个sping的配置文件applicationContext-server.xml  名字可以根据自己习惯修改,内容如下

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd"> <!-- 配置自动扫描的包 -->
<!--
<context:component-scan base-package="com.service.springmvc"></context:component-scan> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean> <bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
<property name="baseAddress" value="http://localhost:8085/"/>
</bean>
-->
<!-- 此次在这里配置,可以设置配置文件
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
-->
<bean id="studentWsImpl" class="com.myl.service.serviceImpl.StudentWsImpl"></bean> <jaxws:server id="studentWsSpring" serviceClass="com.myl.service.StudentWs" address="/StudentSpringWs">
<jaxws:serviceBean>
<ref bean="studentWsImpl"></ref>
</jaxws:serviceBean>
</jaxws:server> </beans>

这里xml 配置文件里面,  bean id 指定了web service 接口实现类,也就是调用接口后实际业务逻辑的实现类;  server id 和address 是 web service接口暴露的地址,对应的是接口类 StudentWs, 而这个服务的serviceBean 指定为接口实现类,这样就指定了运行时调用的实现类。  这个配置也就是sping核心的ioc控制反转功能,通过配置文件将依赖的对象,用配置文件来实现依赖注入,从而实现控制反转。

5、修改web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>SpringCXF</display-name>
<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>
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>cxfService</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cxfService</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

context-param里面指定了spring 配置文件

6、发布到tomcat里面

7、 运行tomcat,如下图所示在表示运行成功

8、查看发布的服务

通过下面url ,来查看发布的服务:http://localhost:8080/SpringCXF/service/   这里StudyWsSpringCXF是工程项目的名称,如果一切正常,打开的界面如下:

9、可以点击红框中内容获取wsdl 文档。

10、通过客户端验证

运行之前的客户端,验证一下发布的服务端能正常工作,需要注意的是,需要修改客户端类StudentWsClient.java里面调用服务端的地址,与当前发布的服务端一致

jwpfb.setAddress("http://localhost:8080/SpringCXF/service/StudentSpringWs");

package com.client;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.webservice.StudentWs; /**
*
* @author myl
* @date 2018年4月18日 上午2:44:26
* 客户端调用服务端发布的接口
*/
public class StudentSerivceTest { public static void main(String[] args) {
//获取工厂对象
JaxWsProxyFactoryBean jwpfb = new JaxWsProxyFactoryBean();
//加载生成的StudentWsImpl类
jwpfb.setServiceClass(StudentWs.class);
//传入url接口地址
jwpfb.setAddress("http://localhost:8080/SpringCXF/service/StudentSpringWs");
//创建接口对象
StudentWs ws = (StudentWs) jwpfb.create();
//调用接口中的方法
ws.addStudentService("mao", "11", "22");
ws.addStudentService("ya", "15", "23");
ws.queryStudentService("mao");
ws.queryStudentService("ya"); } }

运行客户端输出结果:

总结

通过sping+tomcat+cxf 发布webservice 服务的步骤如下:

1、建立工程、编写web service 服务端相应的代码,实现业务逻辑

2、编写sping的配置文件 applicationContext.xml 文件,这个文件放在src 的根目录下

3、编写配置web.xml 文件

4、发布到tomcat中、并进行调试

WebService学习总结(六)--CXF 与Spring结合+tomcat发布的更多相关文章

  1. Webservice实践(七)CXF 与Spring结合+tomcat发布

    上一节介绍了如何使用CXF 来发布服务,但是没有介绍使用web 容器来发布,很多项目需要用tomcat 这样的容器来发布.另外本节将介绍CXF 与spring 结合的方法. 一 目标: 1.利用spi ...

  2. WebService—CXF整合Spring实现接口发布和调用过程

    一.CXF整合Spring实现接口发布 发布过程如下: 1.引入jar包(基于maven管理) <!-- cxf --> <dependency> <groupId> ...

  3. 使用Spring和Tomcat发布CXF REST WebService

    与发布SOAP WS一样, 同样需要在web.xml文件中配置CXFServlet: <!--cxf的Servlet--> <servlet> <servlet-name ...

  4. 使用Spring和Tomcat发布CXF SOAP WebService

    上一节中使用代理工厂JaxWsProxyFactoryBean来发布WebService, 这种方式必须指定运行的端口,如果端口被占用,就会发布失败. cxf的WebService也可利用Tomcat ...

  5. WebService -- Java 实现之 CXF ( 使用Spring添加拦截器)

    最重要的就是在ApplicationContext.xml下面添加配置 <!-- service provider --> <jaxws:endpoint implementor=& ...

  6. Docker学习(六)-Kubernetes - Spring Boot 应用

    接上一篇 https://www.cnblogs.com/woxpp/p/11872155.html 新建 k8s-demo.yaml apiVersion: apps/v1beta2 kind: D ...

  7. WebService学习之旅(一)使用JAX-WS发布WebService

    JAX-WS全称Java™ API for XML Web Services,是随着JDK1.6及其后续版本发布的方便Java程序员开发WebService应用的一组API,通常简称为JWS,目前版本 ...

  8. maven版cxf集合spring开发服务端(二)

    一.新建一个maven项目 二.pom.xml引入依赖 <dependency> <groupId>org.apache.cxf</groupId> <art ...

  9. WebService学习之三:spring+cxf整合

    步骤一:spring项目(java web项目)引入CXF jar包 步骤二:创建webservice服务器 1)创建一个服务接口 package com.buss.app.login; import ...

随机推荐

  1. 【阿菜用工具】Slither:Solidity静态分析框架

    工具简介 Slither 是一个 python3 开发,用于检测智能合约(solidity)漏洞的静态分析框架. Slither 的 Github 地址:https://github.com/cryt ...

  2. etcd学习(5)-etcd的Raft一致性算法原理

    ETCD的Raft一致性算法原理 前言 Raft原理了解 raft选举 raft中的几种状态 任期 leader选举 日志复制 安全性 leader宕机,新的leader未同步前任committed的 ...

  3. DC-3靶机

    仅供个人娱乐 靶机信息 下载地址:http://www.five86.com/downloads/DC-3.zip 一.主机扫描 arp-scan -l nmap -A -p 1-65535 -sV ...

  4. WebRTC 用例和性能

    WebRTC 用例和性能 实现低延迟.点对点传输是一项艰巨的工程挑战:有 NAT 遍历和连接检查.信令.安全.拥塞控制和无数其他细节需要处理.WebRTC 代表我们处理以上所有内容,这就是为什么它可以 ...

  5. CS229 斯坦福大学机器学习复习材料(数学基础) - 线性代数

    CS229 斯坦福大学机器学习复习材料(数学基础) - 线性代数 线性代数回顾与参考 1 基本概念和符号 1.1 基本符号 2 矩阵乘法 2.1 向量-向量乘法 2.2 矩阵-向量乘法 2.3 矩阵- ...

  6. JUC学习笔记(二)

    JUC学习笔记(一)https://www.cnblogs.com/lm66/p/15118407.html 1.Lock接口 1.1.Synchronized 1.1.1.Synchronized关 ...

  7. 音视频开发之H.264 入门知识

    大家如果有做过音视频相关的项目,那么肯定对 H.264 相关的概念了解的比较通透,这里我为什么还要写这样一篇文章呢?一来是为了对知识的总结,二来是为了给刚入门音视频的同学一个参考. 基础概念 H.26 ...

  8. 【odoo】【知识点】生成pdf文件时缺少样式的问题

    欢迎转载,但需标注出处,谢谢! 背景 近期在客户的项目中发现在自定义报表样式的时候,存在渲染为html正常,但是在生成pdf的时候,缺少样式的情况. 分析 涉及到的odoo源码中的ir_actions ...

  9. thunderbird发送纯文本邮件

    向邮件列表中发邮件时,要求邮件格式必须是纯文本格式的,在thunderbird中,邮件格式(plain text或者html格式)在[工具->账户设置->[账户名称]->通讯录]下的 ...

  10. IDM-下载工具

    下载所需要的工具 1.IDM下载地址 链接:https://pan.baidu.com/s/1bHXA0pUYBOAC5f_2Iqvl_g 提取码:lsha 2.IDM破解包下载地址 链接:https ...