服务端:

服务端和客户端都需要引入包

 antlr-2.7.7.jar
aopalliance-1.0.jar
asm-3.3.jar
commons-collections-3.2.1.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
cxf-2.4.2.jar
cxf-manifest.jar
cxf-xjc-boolean-2.4.0.jar
cxf-xjc-bug671-2.4.0.jar
cxf-xjc-dv-2.4.0.jar
cxf-xjc-ts-2.4.0.jar
FastInfoset-1.2.9.jar
geronimo-activation_1.1_spec-1.1.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.7.1.jar
geronimo-jaxws_2.2_spec-1.0.jar
geronimo-jms_1.1_spec-1.1.1.jar
geronimo-servlet_3.0_spec-1.0.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.3.jar
isorelax-20030108.jar
jaxb-api-2.2.1.jar
jaxb-impl-2.2.1.1.jar
jaxb-xjc-2.2.1.1.jar
jettison-1.3.jar
jetty-continuation-7.4.5.v20110725.jar
jetty-http-7.4.5.v20110725.jar
jetty-io-7.4.5.v20110725.jar
jetty-security-7.4.5.v20110725.jar
jetty-server-7.4.5.v20110725.jar
jetty-util-7.4.5.v20110725.jar
joda-time-1.6.2.jar
jra-1.0-alpha-4.jar
js-1.7R2.jar
jsr311-api-1.1.1.jar
msv-core-2010.2.jar
neethi-3.0.1.jar
opensaml-2.4.1.jar
openws-1.4.1.jar
relaxngDatatype-20020414.jar
saaj-api-1.3.jar
saaj-impl-1.3.2.jar
serializer-2.7.1.jar
slf4j-api-1.6.1.jar
slf4j-jdk14-1.6.1.jar
spring-aop-3.0.5.RELEASE.jar
spring-asm-3.0.5.RELEASE.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar
spring-core-3.0.5.RELEASE.jar
spring-expression-3.0.5.RELEASE.jar
spring-jms-3.0.5.RELEASE.jar
spring-tx-3.0.5.RELEASE.jar
spring-web-3.0.5.RELEASE.jar
stax2-api-3.1.1.jar
velocity-1.7.jar
woodstox-core-asl-4.1.1.jar
wsdl4j-1.6.2.jar
wss4j-1.6.2.jar
xalan-2.7.1.jar
xml-resolver-1.2.jar
xmlbeans-2.4.0.jar
xmlschema-core-2.0.jar
xmlsec-1.4.5.jar
xmltooling-1.3.1.jar
xsdlib-2010.1.jar

web.xml

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 两种方式配置1.监听器配置 2.servlet配置, 以下的是采用监听器配置的 --> <!-- 通过上下文参数指定spring配置文件的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:cxf-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 配置CXF框架的核心Servlet -->
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<!-- 通过初始化参数指定配置文件的位置 -->
<!--
<init-param>
<param-name>config-location</param-name>
<param-value>classpath:cxf-servlet.xml</param-value>
</init-param>
-->
</servlet> <servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/cxf/*</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

cxf-servlet.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:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd
">
<!-- 引入CXF Bean定义如下,早期的版本中使用,如果是servlet引入的话则下面三句不用了,因为框架引入了 -->
<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" /> <!-- 通过spring配置文件发布CXF的服务 --> <!-- 第一种发布方式:没有接口的发布(简单发布) -->
<!--
id:唯一标识
address:访问url
implementor:提供服务的类型
-->
<jaxws:endpoint id="helloService" address="/hello"
implementor="cn.itcast.cxf.HelloService">
<!-- 加入消息拦截器 -->
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:endpoint> <!-- 第二种发布方式:带有接口的发布 -->
<!--
id:唯一标识
address:访问url
serviceClass:接口类型
-->
<jaxws:server id="hiService" address="/hi"
serviceClass="cn.itcast.cxf.IHiService">
<jaxws:serviceBean>
<!-- 提供服务的实现类 -->
<bean class="cn.itcast.cxf.HiServiceImpl"></bean>
</jaxws:serviceBean> <!-- 加入消息拦截器 -->
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:server> <!-- 配置restful方式的web服务 -->
<bean id="ps" class="cn.itcast.restful.PersonServiceImpl"></bean>
<jaxrs:server id="personService" address="/p">
<jaxrs:serviceBeans>
<ref bean="ps"/>
</jaxrs:serviceBeans>
<jaxrs:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxrs:inInterceptors>
<jaxrs:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"></bean>
</jaxrs:outInterceptors>
</jaxrs:server>
</beans>

忽略60-72 那是 jason方面的配置

IHiService.java

 package cn.itcast.cxf;

 import javax.jws.WebService;

 @WebService
public interface IHiService {
public String sayHi(String name);
}

HiServiceImpl.java

 package cn.itcast.cxf;

 public class HiServiceImpl implements IHiService {

     @Override
public String sayHi(String name) {
System.out.println("sayHi....");
return "hi " + name;
} }

然后

localhost:8080/项目地址/hi?xsdl

客户端

利用 wsimport -s 地址 或者ws2java -s地址的命令

得到文件后

把接口文件复制来

配置文件 ClientBean.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:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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">
<!-- 配置客户端bean -->
<!--
id:唯一标识
address:请求的服务地址
serviceClass:客户端接口
-->
<jaxws:client id="hiService" address="http://localhost/CXF_03/cxf/hi" serviceClass="cn.itcast.cxf.IHiService"></jaxws:client> </beans>

测试 IHiService就是拷贝过来的接口文件,放到项目中

 package cn.itcast.test;

 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import cn.itcast.cxf.IHiService; public class Test1 {
public static void main(String[] args) {
//初始化spring
ApplicationContext ctx = new ClassPathXmlApplicationContext("ClientBeans.xml");
IHiService s = (IHiService) ctx.getBean("hiService");
s.sayHi("abc");
System.out.println(s.getClass().getName());
}
}

搭建web项目结合spring+cxf的webservice服务的更多相关文章

  1. 在web项目中使用cxf开发webservice,包含spring支持

    本文主要介绍了,如何使用cxf内置的例子,学会开发webserivce,在web项目中使用,且包含spring支持. webserivce的开发可以使用cxf或者axis,好像还有httpclient ...

  2. Eclipse+Maven+Spring+CXF 构建webservice 服务

    一. 软件准备 Eclipse 4.2.1 Maven 2.2.1 Spring 3.2.6 CXF 3.0.2 二. 步骤 首先,在Eclipse中用maven构建一个quickstart版本的ma ...

  3. jfinal集成spring cxf做webservice服务

    链接地址:http://zhengshuo.iteye.com/blog/2154047 废话不说,直接上代码 新增cxf的plugin CXFPlugin package com.jfinal.pl ...

  4. Spring Boot入门-快速搭建web项目

    Spring Boot 概述: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...

  5. Spring Boot搭建Web项目常用功能

    搭建WEB项目过程中,哪些点需要注意: 1.技术选型: 前端:freemarker.vue 后端:spring boot.spring mvc 2.如何包装返回统一结构结果数据? 首先要弄清楚为什么要 ...

  6. Spring Boot 使用 CXF 调用 WebService 服务

    上一张我们讲到 Spring Boot 开发 WebService 服务,本章研究基于 CXF 调用 WebService.另外本来想写一篇 xfire 作为 client 端来调用 webservi ...

  7. Spring-Boot快速搭建web项目详细总结

    最近在学习Spring Boot 相关的技术,刚接触就有种相见恨晚的感觉,因为用spring boot进行项目的搭建是在太方便了,我们往往只需要很简单的几步,便可完成一个spring MVC项目的搭建 ...

  8. springBoot 搭建web项目(前后端分离,附项目源代码地址)

    springBoot 搭建web项目(前后端分离,附项目源代码地址)   概述 该项目包含springBoot-example-ui 和 springBoot-example,分别为前端与后端,前后端 ...

  9. 使用idea+springboot+Mybatis搭建web项目

    使用idea+springboot+Mybatis搭建web项目 springboot的优势之一就是快速搭建项目,省去了自己导入jar包和配置xml的时间,使用非常方便. 1.创建项目project, ...

随机推荐

  1. linux命令: Netstat

    在Internet RFC标准中,Netstat的定义是: Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告.    Netstat是控 ...

  2. java多线程知识点汇总(四)多线程知识点脉络图

    1.多线程安全问题 1)synchronized关键字:如何加锁的问题,选择synchronized方法还是synchnized代码块. 选择哪个锁问题,this对象,还是class对象(针对stat ...

  3. python 将有序list打乱

    利用random模块下的shuffle函数就能够实现. 关于官网对于shuffle,我感觉说法上有一定的误解. 上面是官网的解释,他说会返回打乱的list,事实上什么也没有返回. 能够看到返回的是No ...

  4. serverbash漏洞修补日记——2014/09/30

    近期bash漏洞在网上闹得沸沸扬扬的,我也修补一下.以防万一. 须要用到的命令: 查看操作系统版本号:cat /etc/issue 查看bash版本号:bash -version 查看操作系统是64位 ...

  5. 使用Struts2服务端与android交互

    转自:http://www.cnblogs.com/android-html5/archive/2011/09/25/2534107.html android--使用Struts2服务端与androi ...

  6. [翻译] YLGIFImage 高效读取GIF图片

    YLGIFImage 高效读取GIF图片 https://github.com/liyong03/YLGIFImage Asynchronized GIF image class and Image ...

  7. lodop同一页面一次性打印多次

    怎么让打印机打印双份?lodop有设置吗?SET_PRINT_COPIES名称:设置打印份数格式:SET_PRINT_COPIES(intCopies)功能:设置本次打印的份数结果:返回逻辑结果,成功 ...

  8. hdu 1398

    题目大意:输入是一个整数.输出他的拆分数(即拆分的方案数),本题与1028最大的不同之处就在于他的面额只能是整数的平方 代码如下: /* * 1398_1.cpp * * Created on: 20 ...

  9. 6)Linux程序设计入门--消息管理

    )Linux程序设计入门--消息管理 前言:Linux下的进程通信(IPC) Linux下的进程通信(IPC) POSIX无名信号量 System V信号量 System V消息队列 System V ...

  10. linux系统安装gcc

    安装nginx时会遇到错误提示gcc: command not found,需要先安装gcc 在centos7上安装成功. # yum group list # yum group install & ...