使用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的安装 ...
随机推荐
- (转)SQL流程控制语句学习(一):变量及控制语句种类
1.局部变量 用户自己定义的,称局部变量,以@标识. 作用范围:定义局部变量的批处理.存储过程.触发器和语句块 局部变量的定义: declare @局部变量名 数据类型 注意:变量的类型不能是text ...
- (转)关于c#中的事件
原文链接http://blog.csdn.net/joyhen/article/details/8500211 如有不明白的地方欢迎加QQ群14670545 探讨 最近在看委托,然后看到事件,以前一直 ...
- Android学习手记(2) Activity生命周期
1. 单个Activity的生命周期 当只有一个Activity的时候, 首先执行onCreate->onStart->onResume. 这时, 窗口便显示在屏幕上了. 然后我们按返回键 ...
- UIVIew之霓虹灯实现
// // AppDelegate.m // NiHongPractice // #import "AppDelegate.h" #define kColorValue arc4r ...
- ubuntu 安装 maven3
sudo add-apt-repository ppa:natecarlson/maven3 sudo apt-get update && sudo apt-get install m ...
- Ehcache入门(一)——开发环境的搭建
EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. 那么.如何搭建Ehcache的开发环境呢? 1.下载相关的jar包,这 ...
- String的format方法
摘自:http://xiongzhenhui.iteye.com/blog/940416 http://blueram.iteye.com/blog/441683 一.常规类型.字符类型和数值类型的格 ...
- 3D 灯光介绍
光特性 参考OpenGL的光照模型,把光分成4种独立的成分: 环境光 散射光 镜面光 发散光 环境光:ambient light 环境光是那些在环境中进行了充分的散射,无法分辨其方向的光.它会均匀的照 ...
- apache2.2 虚拟主机配置详解
一.修改httpd.conf 打开appserv的安装目录,找到httpd.conf文件,分别去掉下面两行文字前面的#号. #LoadModule vhost_alias_module modules ...
- Js打开网页后居中显示
使用JavaScript定义打开网页后居中显示,并可为窗口设置大小,使用“window.open”方法打开新窗口:先来看完整的代码及调用方法: <html xmlns="http:// ...