搭建web项目结合spring+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.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服务的更多相关文章
- 在web项目中使用cxf开发webservice,包含spring支持
本文主要介绍了,如何使用cxf内置的例子,学会开发webserivce,在web项目中使用,且包含spring支持. webserivce的开发可以使用cxf或者axis,好像还有httpclient ...
- 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 ...
- jfinal集成spring cxf做webservice服务
链接地址:http://zhengshuo.iteye.com/blog/2154047 废话不说,直接上代码 新增cxf的plugin CXFPlugin package com.jfinal.pl ...
- Spring Boot入门-快速搭建web项目
Spring Boot 概述: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...
- Spring Boot搭建Web项目常用功能
搭建WEB项目过程中,哪些点需要注意: 1.技术选型: 前端:freemarker.vue 后端:spring boot.spring mvc 2.如何包装返回统一结构结果数据? 首先要弄清楚为什么要 ...
- Spring Boot 使用 CXF 调用 WebService 服务
上一张我们讲到 Spring Boot 开发 WebService 服务,本章研究基于 CXF 调用 WebService.另外本来想写一篇 xfire 作为 client 端来调用 webservi ...
- Spring-Boot快速搭建web项目详细总结
最近在学习Spring Boot 相关的技术,刚接触就有种相见恨晚的感觉,因为用spring boot进行项目的搭建是在太方便了,我们往往只需要很简单的几步,便可完成一个spring MVC项目的搭建 ...
- springBoot 搭建web项目(前后端分离,附项目源代码地址)
springBoot 搭建web项目(前后端分离,附项目源代码地址) 概述 该项目包含springBoot-example-ui 和 springBoot-example,分别为前端与后端,前后端 ...
- 使用idea+springboot+Mybatis搭建web项目
使用idea+springboot+Mybatis搭建web项目 springboot的优势之一就是快速搭建项目,省去了自己导入jar包和配置xml的时间,使用非常方便. 1.创建项目project, ...
随机推荐
- Codeforces Beta Round #9 (Div. 2 Only) A. Die Roll 水题
A. Die Roll 题目连接: http://www.codeforces.com/contest/9/problem/A Description Yakko, Wakko and Dot, wo ...
- Codeforces Round #302 (Div. 1) C. Remembering Strings DP
C. Remembering Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- IOS上传图片方法类
IOS上传图片方法类 iPhone开发中遇到上传图片问题,找到多资料,最终封装了一个类,请大家指点,代码如下 // // RequestPostUploadHelper.h // demodes ...
- 利用Lucene与Nutch构建简单的全文搜索引擎
文章地址 1.简介 本次实现分为两个部分,第一个部分是利用Lucene构建一个全文的搜索引擎,另外一部分则是利用Nutch实现同样的功能.由于Lucene并不是一个可以直接运行的程序,且不具备爬虫和文 ...
- source insight完全卸载
由于不知名原因 source insight崩溃了,使用自带的卸载,完成之后重新安装软件注册还是出问题.在网上搜索资料发现就是删除注册表中的内容. 由于列出的删除项目不完全,导致还是出问题. 最后删除 ...
- python使用游标访问数据
游标是一种数据访问对象,可用于在表中迭代一组行或者向表中插入新行.游标有三种形式:搜索.插入或更新.游标通常用于读取现有几何和写入新几何. 每种类型的游标均由对应的 ArcPy 函数(SearchCu ...
- Ubuntu OS应用Runtime Enviroment
在这篇文章中.我们将介绍Ubuntu OS的Runtime Environment.在文章"App confinement: Security policy for click packag ...
- Android学习进阶和IoC
1.成为Android高手一般分为六个阶段: 第一阶段:熟练掌握Java SE,尤其是对其内部类.线程.并发.网络编程等需要深入研究:熟练掌握基于HTTP协议的编程,清楚POST和GET等请求方式流程 ...
- mysql中避免使用保留字和关键字做列的名字
设计数据表时,应尽量避免使用MySQL的关键字和保留字作为表名或列名. 比如key和keys为保留字,如果不小心使用关键字或者保留字作为列名字,执行下面的语句会出现语法错误: select * fro ...
- iOS:下拉刷新控件UIRefreshControl的详解
下拉刷新控件:UIRefreshControl 1.具体类信息: @interface UIRefreshControl : UIControl //继承控制类 - (instancetype)ini ...