使用CXF+spring创建一个web的接口项目
一、web project整合spring
1.1、打开Myeclipse,建立web project(eclipse为dynamic web project),使用J2EE5.0。
1.2、加入Srping的基本jar包(无需事务等)
org.springframework.beans-3.1.1.RELEASE.jar
commons-logging.jar
org.springframework.aop-3.1.1.RELEASE.jar
org.springframework.asm-3.1.1.RELEASE.jar
org.springframework.beans-3.1.1.RELEASE.jar
org.springframework.context-3.1.1.RELEASE.jar
org.springframework.context.support-3.1.1.RELEASE.jar
org.springframework.core-3.1.1.RELEASE.jar
org.springframework.expression-3.1.1.RELEASE.jar
org.springframework.orm-3.1.1.RELEASE.jar
org.springframework.web-3.1.1.RELEASE.jar
javassist-3.11.0.GA.jar
1.3、新建源文件夹(source folder)conf,位于项目下,加入applicationContext.xml到该文件夹,内容例如以下:
<?xml version="1.0"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
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/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd "> </beans>
1.4、在web.xml中web-app节点下加入监听,例如以下:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
执行项目,正常执行则说明正常。
二、开发webservice服务
新建RegeditService类,例如以下:
package zxn.ws.service; import javax.jws.WebParam;
import javax.jws.WebService; @WebService
public interface RegeditService {
/**
* 注冊方法
* @param username
* @param password
* @return
*/
public String regedit(@WebParam(name = "username")String username, @WebParam(name="password")String password);
}
新建RegeditServiceImpl类,例如以下:
package zxn.ws.service; import javax.jws.WebService; @WebService(endpointInterface="zxn.ws.service.RegeditService",serviceName="Regedit", targetNamespace="http://service.ws.zxn/")
public class RegeditServiceImpl implements RegeditService {
/**
* 注冊方法
* @param username
* @param password
* @return
*/
public String regedit(String username, String password) {
return username+",你已成功注冊!";
}
}
注意:targetNamespace中的包名倒着写,最后要加"/",否则报错。
三、spring整合cxf
3.1、加入jar包
cxf-2.7.8.jar
neethi-3.0.2.jar
xmlschema-core-2.0.3.jar
wsdl4j-1.6.3.jar
asm-3.3.jar
3.2、applicationContext.xml中加入例如以下内容:
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- webservice配置 ,myeclipse可能检測到此处有错没影响-->
<jaxws:endpoint id="regeditService" implementor="zxn.ws.service.RegeditServiceImpl" address="/Regedit" />
3.3、在web.xml中加入例如以下cxf配置:
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
部署到tomcat,訪问地址:http://localhost:8080/CXFWS/services(最后的services是3.3中配置的訪问路径),例如以下图则表示成功:
wsdl文档例如以下图:
另附上源码地址:http://download.csdn.net/detail/zxnlmj/7457693
使用CXF+spring创建一个web的接口项目的更多相关文章
- 十七、创建一个 WEB 服务器(一)
1.Node.js 创建的第一个应用 var http=require("http") http.createServer(function (req,res) { res.wri ...
- Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目
Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...
- 002.Create a web API with ASP.NET Core MVC and Visual Studio for Windows -- 【在windows上用vs与asp.net core mvc 创建一个 web api 程序】
Create a web API with ASP.NET Core MVC and Visual Studio for Windows 在windows上用vs与asp.net core mvc 创 ...
- 使用eclipse插件创建一个web project
使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 ...
- C#中自己动手创建一个Web Server(非Socket实现)
目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 ...
- eclipes创建一个web项目web.xml不能自动更新的原因(web.xml和@WebServlet的作用)
在eclipse中创建一个Web项目的时候,虽然有web.xml生成,但是再添加Servlet类文件的时候总是看不见web.xml的更新,所以异常的郁闷!上网查了查,原来我们在创建Web项目的时候,会 ...
- 【重点突破】——使用Express创建一个web服务器
一.引言 在自学node.js的过程中有一个非常重要的框架,那就是Express.它是一个基于NodeJs http模块而编写的高层模块,弥补http模块的繁琐和不方便,能够快速开发http服务器.这 ...
- 【LINUX】——linux如何使用Python创建一个web服务
问:linux如何使用Python创建一个web服务? 答:一句话,Python! 一句代码: /usr/local/bin/python -m SimpleHTTPServer 8686 > ...
- Intellij Idea 创建一个Web项目
今天想用IDEA创建一个web项目: 准备工具 1.jdk1.7 2.tomcat6.0,由于下载的8.5没有lib目录不能配置改6.0 3.idea2019.1.2 Intellij Idea的安装 ...
随机推荐
- GridView、Repeater获取当前行号
GridView: <%# Container.DataItemIndex+1 %> Repeater:<%# Container.ItemIndex+1%>
- RecyclerView更通用——listView的onItemClick,onLongItemClick,addHeaderView,addFooterView
一.点击事件 setOnItemClickListener,setOnItemLongClickListener RecyclerView中虽然没有提供上面这两个接口,但是给我们提供了另外一个接口:O ...
- 对于没有Command属性时,怎么来达到相同的效果
控件是第三方Telerik控件 CellEditEnded事件想写成Command{Binding CellEditEndedCommand} 这样的效果如下代码 需要引用 System.Wind ...
- 关于<%@ include file=" " %>与<jsp:include page=""></jsp:include>中的那些问题?
今天在使用<%@ include file=" " %>指令时,竟然在页面中不让使用?这是怎么回事:问题如下图: 顿时被这个问题给搞到了!!!突然想到在以前的 JSP ...
- python记录
1. 序列的分片操作:需要提供两个索引作为边界,第1个索引的元素包含在分片内,第2个索引的元素不包含在分片内. 为了能让分片部分能够包含列表的最后一个元素,必需提供最后一个元素的下一个元素所对应的索引 ...
- PHPCMSV9 采集网址后,再采集内容,报错:“采集采集内容 没有找到网址列表,请先进行网址采集”
解决方法:直接清除v9_collection_history 表里的内容.
- ubuntu 引导删除
点开始,在搜索中输入cmd,在搜到的cmd上右键以管理员身份运行,在打开的cmd中输入命令:bcdedit在命令结果中找到类似如下的版块: 实模式启动扇区---------------------标识 ...
- c语言实现BMP图像转换为灰度图
当初是自己要装X,非要用c来写信息隐藏作业,装了X,就得付出实践.查了好久资料,到期末才把作业交了,这里总结一下. 这道题是将真彩图转换为灰度图. 关于BMP文件结构,这是困扰了我好久的问题,上网查了 ...
- [转]100个经典C语言程序(益智类问题)
目录: 1.绘制余弦曲线 2.绘制余弦曲线和直线 3.绘制圆 4.歌星大奖赛 5.求最大数 6.高次方数的尾数 8.借书方案知多少 9.杨辉三角形 10.数制转换 11.打鱼还是晒网 12.抓交通肇事 ...
- 【学习笔记】【Foundation】集合Set
不可变集合 NSSet :集合元素无顺序,没有索引号,元素不可重复. NSSet在功能上可看做是NSArray的父集,它是一个更通用的类. NSSet包含如下常用方法: setByAddingObje ...