一、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的接口项目的更多相关文章

  1. 十七、创建一个 WEB 服务器(一)

    1.Node.js 创建的第一个应用 var http=require("http") http.createServer(function (req,res) { res.wri ...

  2. Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目

    Spring MVC 学习笔记2 - 利用Spring Tool Suite创建一个web 项目 Spring Tool Suite 是一个带有全套的Spring相关支持功能的Eclipse插件包. ...

  3. 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 创 ...

  4. 使用eclipse插件创建一个web project

    使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 ...

  5. C#中自己动手创建一个Web Server(非Socket实现)

    目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 ...

  6. eclipes创建一个web项目web.xml不能自动更新的原因(web.xml和@WebServlet的作用)

    在eclipse中创建一个Web项目的时候,虽然有web.xml生成,但是再添加Servlet类文件的时候总是看不见web.xml的更新,所以异常的郁闷!上网查了查,原来我们在创建Web项目的时候,会 ...

  7. 【重点突破】——使用Express创建一个web服务器

    一.引言 在自学node.js的过程中有一个非常重要的框架,那就是Express.它是一个基于NodeJs http模块而编写的高层模块,弥补http模块的繁琐和不方便,能够快速开发http服务器.这 ...

  8. 【LINUX】——linux如何使用Python创建一个web服务

    问:linux如何使用Python创建一个web服务? 答:一句话,Python! 一句代码: /usr/local/bin/python -m SimpleHTTPServer 8686 > ...

  9. Intellij Idea 创建一个Web项目

    今天想用IDEA创建一个web项目: 准备工具 1.jdk1.7 2.tomcat6.0,由于下载的8.5没有lib目录不能配置改6.0 3.idea2019.1.2 Intellij Idea的安装 ...

随机推荐

  1. cassandra新增、更新、删除数据。

    package client; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java ...

  2. 关于phonegap

    phonegap安卓环境搭建: http://www.cnblogs.com/Random/archive/2011/12/28/2305398.htmlhttp://ningtukun.blog.1 ...

  3. SQL2008 存储过程参数相关

      使用inputparame时,使用的是 varchar(20),和数据库中的DEPARTNAME完全匹配,可以查出值: USE [test] GO SET ANSI_NULLS OFF GO SE ...

  4. spring 配置触发器 (类似于定时任务)

    为什么会看这个? 发现项目中有的service中的方法没有地方调用.经查,发现在web.xml中加载的spring的配置文件中配置了这个方法, 经查这种方式是触发器,会定时执行,只需要配置一下.可以设 ...

  5. Swift语言 代码添加文本输入框 和 占位文本

    //懒加载文本输入框 private lazy var textView: UITextView = { let textView = UITextView() textView.font = UIF ...

  6. uva 10154 贪心+dp

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  7. addChildViewController 用法

    // // SCMyOrderViewController.m // SmartCommunity // // Created by chenhuan on 15/9/7. // Copyright ...

  8. 《Javascript模式》之对象创建模式读书笔记

    引言: 在javascript中创建对象是很容易的,可以使用对象字面量或者构造函数或者object.creat.在接下来的介绍中,我们将越过这些方法去寻求一些其他的对象创建模式. 我们知道js是一种简 ...

  9. 《python基础教程》笔记之 列表

    list函数 list函数将其他类型的序列转换为列表,如 >>> list("hello world")['h', 'e', 'l', 'l', 'o', ' ' ...

  10. MVC中修改报错

    修改的时候有空值传入.