背景:maven构建的springMvc+mybatis框架

源码---》https://github.com/Zering/MyWeb

步骤:(本步骤是自己在实际探索过程中的步骤,我的思路是先简单粗暴的写出方法,报错了再根据错误来解决问题)

  第一步:直接写出了接口和实现类

  示例接口代码

package com.app.service;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style; @WebService
@SOAPBinding(style = Style.RPC)
public interface IWebService { public String sayHello(String string);
}

  示例实现类方法

package com.app.service.impl;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style; import org.springframework.stereotype.Service; import com.app.service.IWebService; @Service
@WebService(endpointInterface="com.app.service.IWebService",serviceName="webservice1")
@SOAPBinding(style = Style.RPC)
public class WebserviceImpl implements IWebService { @Override
public String sayHello(String string) {
return "hello "+string;
} }

  第二步:写cxf的配置信息,创建一个application-cxf.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-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
default-autowire="byName"> <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="inMessageInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> <jaxws:endpoint implementor="com.app.service.impl.WebserviceImpl" address="/webservice1"></jaxws:endpoint> </beans>

  注意:这个文件里面的三个<import>是从jar包中导入的,所以在classpath后面一定要加*号

  步骤三:修改web.xml

    1.修改<context-param>

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:spring-mybatis.xml classpath:application-cxf.xml</param-value>
</context-param>

    2.追加一个webservice的servelet

    <!-- For WebService -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/WebService/*</url-pattern>
</servlet-mapping>

  步骤四:这个时候启动tomcat的话,会有异常说缺啥缺啥的,根据这个信息来导入相应的jar包,加的jar包如下:

    <dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>apache-cxf</artifactId>
  <version>3.1.6</version>
  <type>pom</type>
    </dependency>
    <dependency>
       <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-bindings-soap</artifactId>
  <version>3.1.6</version>
    </dependency>

  步骤五:验证,启动tomcat,url输入 http://localhost:8080/MyWeb/WebService

    

    完成。

  

  

javaweb学习路之四--cxf发布Webservice的更多相关文章

  1. CXF发布webService服务以及客户端调用

    这篇随笔内容是CXF发布webService服务以及客户端调用的方法 CXF是什么? 开发工作之前需要下载CXF和安装 下载地址:http://cxf.apache.org 安装过程: <1&g ...

  2. SpringBoot整合cxf发布webService

    1. 看看项目结构图 2. cxf的pom依赖 1 <dependency>2 <groupId>org.apache.cxf</groupId>3 <art ...

  3. SpringMVC4整合CXF发布WebService

    SpringMVC4整合CXF发布WebService版本:SpringMVC 4.1.6,CXF 3.1.0项目管理:apache-maven-3.3.3 pom.xml <project x ...

  4. Spring集成CXF发布WebService并在客户端调用

    Spring集成CXF发布WebService 1.导入jar包 因为官方下载的包里面有其他版本的sprring包,全导入会产生版本冲突,所以去掉spring的部分,然后在项目根目录下新建了一个CXF ...

  5. 使用CXF发布WebService

    这里普及一下WebService和cxf的知识.关于webservice和cxf:   WebService.各种提供服务的组件     .企业总线.通讯总线(ESB)CXF:是一个SOA框架,Axi ...

  6. 使用CXF发布WebService服务简单实例

    一.说明: 前面介绍了使用axis2来发布Webservice服务,现在介绍一种更popular,更高效的Webservice服务发布技术:CXF Apache CXF = Celtix + XFir ...

  7. CXF发布webservice入门

    1.设置CXF的bin目录进环境变量 2.CXF导入相关的jar包. 3.建立接口 @WebService public interface HelloWorld { public void say( ...

  8. [置顶] 利用CXF发布webService的小demo

    其实webService的发布不仅仅只有xfire,今天,给大家介绍一下用CXF发布一个webService的小demo,CXF也是我做webService用的第一个框架... 先将相关的jar引进来 ...

  9. cxf发布 webservice服务

    导包 antlr-2.7.7.jar aopalliance-1.0.jar asm-3.3.jar commons-collections-3.2.1.jar commons-lang-2.6.ja ...

随机推荐

  1. Notepad++使用技法

    Alt+H 隐藏行 Ctrl+Tab  实现在多个打开的窗口间切换 Ctrl+Shift+Q区块注释 Ctrl+K行注释(取消Ctrl+Shift+K) 文件  新建文件 Ctrl+N  打开文件 C ...

  2. 本地环境下 WordPress 环境搭建与安装

    本地环境:Ubuntu 14.04 使用软件: WordPress 4.1.1 中文优化版 EasyEngine 安装步骤: 安装 LNMP 环境; wget -qO ee rt.cx/ee & ...

  3. 深入理解urllib、urllib2及requests

    urllib and urllib2 区别 –博主提示:下面的是python2中的用法,python3需要做出相应修改. urllib和urllib2模块都做与请求URL相关的操作,但他们提供不同的功 ...

  4. 用1个 2个3个 5个div实现 十字架

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. JWPlayer 初探

    http://www.360doc.com/content/13/0103/22/21412_258041878.shtml JWPlayer 是一款比较实用的web flash 播放器

  6. openStack icehouse for centos6.4 production Env 实战

    production Env brief Overview: Management Node:  controller.cc 10.114.100.115 Neutron Network Node:  ...

  7. java类的结构(属性、方法、构造函数)

    一.类的定义形式类定义的一般形式如下 [类定义修饰符] class  <类名> {   //类体 [成员变量声明] [构造函数] [成员方法] } 前面说过,在描述java语法时,方括号中 ...

  8. xmu1125 越野车大赛(三分)

    1125: 越野车大赛 Time Limit: 500 MS  Memory Limit: 64 MB  Special JudgeSubmit: 4  Solved: 3[Submit][Statu ...

  9. NHibernate初入门之映射文件配置说明(三)

    转载逆心http://www.cnblogs.com/kissdodog/archive/2013/02/21/2919886.html 1. hibernate-mapping 这个元素包括以下可选 ...

  10. Node.js模块os

    OS 操作系统模块 os.hostname() 操作系统的主机名. os.type() 操作系统的名称 os.release() 操作系统的发行版本 os.uptime() 当前系统的时间 以秒为 o ...