搭建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, ...
随机推荐
- BZOJ 1032 JSOI 2007 祖码Zuma 区间DP
题目大意:依照祖玛的玩法(任意选颜色),给出一段区间.问最少用多少个球可以把全部颜色块都消除. 思路:把输入数据依照连续的块处理.保存成颜色和数量.然后用这个来DP.我们知道,一个单独的块须要两个同样 ...
- Cascode MOSFET increases boost regulator's input- and output-voltage ranges
Targeting use in portable-system applications that require raising a battery's voltage to a higher l ...
- poj 3131 双向搜索+hash判重
题意: 初始状态固定(朝上的全是W,空格位置输入给出),输入初始状态的空格位置,和最终状态朝上的位置,输出要多少步才能移动到,超过30步输出-1. 简析: 每一个格子有6种状态,分别是 0WRB, 1 ...
- ADS-B显示终端6.0
改动日志 1 更新背景地图. 增加了全国范围内的飞行限制区.飞行危急区.限制区採用黄色区域表示.危急区採用红色区域表示.全部原始资料均来自民航局发布的航行情报资料汇编. 2为解决显示元素过多,屏幕显 ...
- Jetty开发指导:WebSocket介绍
WebSocket是一个新的基于HTTP的双向通讯的协议. 它是基于低级别的框架协议.使用UTF-8 TEXT或者BINARY格式传递信息. 在WebSocket中的单个信息能够是不论什么长度(然而底 ...
- windows系统上安装与使用Android NDK r8d(二)
四. 在eclipse中集成c/c++开发环境 1. 装Eclipse的C/C++环境插件:CDT,这里选择在线安装. 首先登录http://www.eclipse.or ...
- nose的测试报告
有时候我们要让报告整洁美观点,以html展示测试结果,我们可以借助pip install nosehtmloutput插件输出html格式报告 from nose.plugins.plugintest ...
- POJ 1737 Connected Graph 题解(未完成)
Connected Graph Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3156 Accepted: 1533 D ...
- HTML:图片和视频标签的使用
介绍:在html网页中,图片和视频是基本的元素,在网页中插入图片和视频有自己的标签,分别是img.embed,来源都是使用src来链接. 插入图片: <img src="图片的来源&q ...
- 如何高效的将excel导入sqlserver?
大部分人都知道用oledb来读取数据到dataset,但是读取之后怎么处理dataset就千奇百怪了.很多人通过循环来拼接sql,这样做不但容易出错而且效率低下,System.Data.SqlClie ...