CXF是一个基于 Servlet 技术的 SOA 应用开发框架,简单来说,就是WebService的轻量级实现。

1、下载开发包:http://cxf.apache.org/download.html,选择相应的版本。

2、在eclipse创建maven web工程。

3、打开开发包实例的:java_first_spring_support,将java,resources, webapp复制到工程。

4、复制pom.xml文件到工程,将工程名称修改成自己创建的工程,如:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jaxws</groupId>
<artifactId>jaxws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>jaxws Maven Webapp</name>
<description>Spring HTTP Sample</description>
<packaging>war</packaging> <properties>
<cxf.version>${project.version}</cxf.version>
<cxf.release.base>${basedir}/../..</cxf.release.base>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
<finalName>JavaFirstSpringSupport</finalName>
</build>
<profiles>
<profile>
<id>server</id>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>demo.spring.service.Server</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>client</id>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>demo.spring.client.Client</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.7.16</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.7.16</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.7.16</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.5.v20120716</version>
</dependency>
</dependencies> </project>

5、完成后目录结构如图:

6、运行项目。

7、配置resouces中client_bean.xml中地址符合你本地的服务,运行Client.java,访问成功。

package demo.spring.client;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import demo.spring.service.HelloWorld;

public final class Client {

    private Client() {
} public static void main(String args[]) throws Exception {
// START SNIPPET: client
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(new String[] {"client-beans.xml"}); HelloWorld client = (HelloWorld)context.getBean("client"); String response = client.sayHi("Joe");
System.out.println("Response: " + response);
System.exit(0);
// END SNIPPET: client
}
}

cxf简单实例的更多相关文章

  1. Hibernate(二)__简单实例入门

    首先我们进一步理解什么是对象关系映射模型? 它将对数据库中数据的处理转化为对对象的处理.如下图所示: 入门简单实例: hiberante 可以用在 j2se 项目,也可以用在 j2ee (web项目中 ...

  2. 最新 Eclipse IDE下的Spring框架配置及简单实例

    前段时间开始着手学习Spring框架,又是买书又是看视频找教程的,可是鲜有介绍如何配置Spring+Eclipse的方法,现在将我的成功经验分享给大家. 本文的一些源代码来源于码农教程:http:// ...

  3. 修改js confirm alert 提示框文字的简单实例

    修改js confirm alert 提示框文字的简单实例: <!DOCTYPE html> <html> <head lang="en"> & ...

  4. 利用navicat创建存储过程、触发器和使用游标的简单实例

    利用navicat创建存储过程.触发器和使用游标的简单实例 标签: navicat存储过程触发器mysql游标 2013-08-03 21:34 15516人阅读 评论(1) 收藏 举报  分类: 数 ...

  5. 【转】Android Https服务器端和客户端简单实例

    转载地址:http://blog.csdn.net/gf771115/article/details/7827233 AndroidHttps服务器端和客户端简单实例 工具介绍 Eclipse3.7 ...

  6. Centos7的安装、Docker1.12.3的安装,以及Docker Swarm集群的简单实例

    目录 [TOC] 1.环境准备 ​ 本文中的案例会有四台机器,他们的Host和IP地址如下 c1 -> 10.0.0.31 c2 -> 10.0.0.32 c3 -> 10.0.0. ...

  7. vue路由的简单实例

    vue2.0 和 vue1.0 路由的语法还是有点稍微的差别,下面介绍一下vue-router 2的简单实例: <!DOCTYPE html> <html lang="en ...

  8. Flume概述和简单实例

    Flume概述 Flume是一个分布式.可靠.和高可用的海量日志采集.聚合和传输的系统.支持在日志系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方( ...

  9. jsoup解析HTML及简单实例

    jsoup 中文参考文献    http://www.open-open.com/jsoup/ 本文将利用jsoup,简单实现网络抓取的功能,并给出一个小实例,该实例效果为:获取作者本人在博客园写的所 ...

随机推荐

  1. [wordpress] determine_current_user 在get_current_user_id() 或者 wp_get_current_user()会调用

    在看了Cookie Authentication In A AngularJS WordPress Theme之后,清楚了当Wordpress在中使用get_current_user_id() 或者w ...

  2. 50个常用的笔试、面试sql语句

    50个常用的笔试.面试sql语句 2009-12-17 15:05   Student(S#,Sname,Sage,Ssex) 学生表Course(C#,Cname,T#) 课程表SC(S#,C#,s ...

  3. js利用数组length属性清空和截短数组

    1.使用length清空数组: 代码如下 复制代码 <script>    var arr1 = ['aaa','bbbb','http://www.111cn.net'];    ale ...

  4. Oracle在所有内容前追加一些内容的方法

     参照下面的sql语句. SQL> SELECT * FROM UserInfo; NAME                    CHINESE -------------------- ...

  5. 【转载】#303 - Accessibility of Class Members

    Members of a class can have different kinds of accessibility. An accessibility keyword indicates wha ...

  6. arcgis js api 本地化配置

    配置arcgis library 根目录的init.js的 "baseUrl:",使其指向正确的地址

  7. 《锋利的jQuery》心得笔记--One Sections

    第一章 1.    $是jQuery的一个简写形式 2.    在jQuery中无法使用DOM对象的任何方法:比如:$ (“#id”).innerHTML.$ (“#id”).checked, 可以使 ...

  8. mysql之触发器trigger(1)

    触发器(trigger):监视某种情况,并触发某种操作. 触发器创建语法四要素:1.监视地点(table) 2.监视事件(insert/update/delete) 3.触发时间(after/befo ...

  9. HIV T2

    甲学者将HIV病毒的遗传物质彻底水解后得到A.B.C三种化合物,乙学者将组成T2噬菌体的遗传物质彻底水解后得到了A.B.D三种化合物.你认为C.D两种化合物分别指的是 A.尿嘧啶.胸腺嘧啶 B.胸腺嘧 ...

  10. const关键字在C和C++区别

    1)C++默认为内部链接:C默认为外部链接2)在C++中,一般一个const不会创建内存空间,而是将其保存在符号表(待看).比如: ; char buf[bufsize]; 这里无需为const创建内 ...