1.搭建Maven环境

参考文章

Maven3路程(一)环境搭建

http://www.cnblogs.com/leiOOlei/p/3359561.html

Maven3路程(二)Eclipse集成Maven

http://www.cnblogs.com/leiOOlei/p/3361379.html

Maven3路程(三)用Maven创建第一个web项目(1)

Maven3路程(三)用Maven创建第一个web项目(2)servlet演示

Maven 配置Spring

参考

http://blog.csdn.net/shiyuezhong/article/details/7959863

重点添加这两个依赖

 <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>

3.Maven 添加 CXF

 <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.0.0</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.0.0</version>
</dependency>

 

最后Web.xml文件是这样

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <display-name>Archetype Created Web Application</display-name>
<!--部署到tomcat中,cxf 的webservice服务就启动了,访问的地址是 xx.com/ws/* -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXFServlet</display-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>/ws/*</url-pattern>
</servlet-mapping> </web-app>

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>com.webtest</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.0.0</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.0.0</version>
</dependency> </dependencies>
<build>
<finalName>test</finalName>
</build>
</project>

applicationContext.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:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <bean id="person" class="test.Person">
<property name="name" value="zhangsan"></property>
<property name="age" value="12"></property>
</bean> <bean id="app" class="test.App">
<property name="person" ref="person"></property>
</bean> <import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <bean id="hello" class="test.HelloWorldImpl" /> <jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" /> </beans>

服务端端生成的服务地址是这样的http://localhost:8080/maventtest1/ws/HelloWorld?wsdl

必须添加?wsdl才可以看到xml信息

 4.CXF生成客户端代码

服务端的cxf的web服务好了以后,就可以暴露给客户端使用,客户端在使用的时候要先生成客户端代码

这个地方有多种方式,我用的CXF自带wsdl2java的工具

在电脑的环境变量中配置CXF_HOME 和配置path路径

然后就可以使用wsdl2java的命令

wsdl2java用法:

wsdl2java -p com -d src -all  http://localhost:8080/maventtest1/ws/HelloWorld?wsdl
-p  指定其wsdl的命名空间,也就是要生成代码的包名:
-d  指定要产生代码所在目录
-client 生成客户端测试web service的代码
-server 生成服务器启动web  service的代码

具体地址是查看参数信息可以参考http://cxf.apache.org/docs/how-do-i-develop-a-client.html#HowdoIdevelopaclient?-WSDL2JavageneratedClient

结果就是生成一个命名空间下的java类集合。

里面会有一个 XXXService的类,调用GetXXPort的方法,会返回原来服务端的一个接口类。就可以调用服务端的服务了

HelloService service = new HelloService();
Hello client = service.getHelloHttpPort();
 
String result = client.sayHi("Joe");
 

Maven 创建java Web项目,配置Spring,CXF的更多相关文章

  1. IntelliJ IDEA + Maven创建Java Web项目

    1. Maven简介 相对于传统的项目,Maven 下管理和构建的项目真的非常好用和简单,所以这里也强调下,尽量使用此类工具进行项目构建, 它可以管理项目的整个生命周期. 可以通过其命令做所有相关的工 ...

  2. 使用IntelliJ IDEA 和 Maven创建Java Web项目

    1. Maven简介 相对于传统的项目,Maven 下管理和构建的项目真的非常好用和简单,所以这里也强调下,尽量使用此类工具进行项目构建, 它可以管理项目的整个生命周期. 可以通过其命令做所有相关的工 ...

  3. Idea使用Maven创建Java Web项目

    最近学到了Java Web项目,使用Idea和Maven创建Java Web的时候遇到了诸多问题,最多的还是404问题.现在记录一下解决方案. 一.使用maven创建一个web项目,这一步网上都有,下 ...

  4. 使用IntelliJ IDEA 15和Maven创建Java Web项目(转)

    1. Maven简介 相对于传统的项目,Maven 下管理和构建的项目真的非常好用和简单,所以这里也强调下,尽量使用此类工具进行项目构建, 它可以管理项目的整个生命周期. 可以通过其命令做所有相关的工 ...

  5. 17. IntelliJ IDEA + Maven创建Java Web项目

    转自:https://www.cnblogs.com/Terry-Wu/p/8006475.html 1. Maven简介 相对于传统的项目,Maven 下管理和构建的项目真的非常好用和简单,所以这里 ...

  6. 使用IntelliJ IDEA 15和Maven创建Java Web项目(转)

    转自:https://blog.csdn.net/myarrow/article/details/50824793 1. Maven简介 相对于传统的项目,Maven 下管理和构建的项目真的非常好用和 ...

  7. Maven配置,使用IntelliJ IDEA和Maven创建Java Web项目

    1. 下载Maven 官方地址:http://maven.apache.org/download.cgi 解压并新建一个本地仓库文件夹 2.配置本地仓库路径   3.配置maven环境变量     4 ...

  8. idea 中利用maven创建java web 项目

    转自:http://www.linuxidc.com/Linux/2014-04/99687.htm 本文主要使用图解介绍了使用IntelliJ IDEA 12创建Maven管理的Java Web项目 ...

  9. 【Maven】Eclipse 使用Maven创建Java Web项目

    创建环境 系统:win 10 软件:eclipse,maven 创建步骤 需求创建一个Servlet版本是3.0,Java版本是1.7的项目Maven web项目 使用eclipse工具创建maven ...

  10. 【Maven】 Eclipse使用Maven创建Java Web 项目(一)

    需求:创建一个Servlet版本3.0,Java版本是1.7的Maven Web项目 创建环境: 系统:window 7 软件:Eclipse.Maven 创建步骤: 1.使用eclipse工具创建m ...

随机推荐

  1. SpringBoot.资料

    1.du 搜 "springboot 视频" 2.SpringBoot视频教程_哔哩哔哩 (゜-゜)つロ 干杯_-bilibili.html(https://www.bilibil ...

  2. 动态规划-Predict the Winner

    2018-04-22 19:19:47 问题描述: Given an array of scores that are non-negative integers. Player 1 picks on ...

  3. Kolakoski数列

    2018-04-16 15:40:16 Kolakoski序列是一个仅由1和2组成的无限数列,是一种通过“自描述”来定义的数列.他在整数数列大全网站上排名第二位,足见该数列在组合数学界中的重要性. K ...

  4. PHP------数组和对象相互转化,stdClass Object转array

    数组转JSON PHP json_encode() 用于对变量进行 JSON 编码,该函数如果执行成功返回 JSON 数据,否则返回 FALSE . JSON转数组 PHP json_decode() ...

  5. hdu 6144 Arithmetic of Bomb

    Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. 【LeetCode 8_字符串_实现】String to Integer (atoi)

    , INVALID}; int g_status; long long SubStrToInt(const char* str, bool minus) { ; : ; while (*str != ...

  7. 1元抢卡巴KAV_不限量疯抢即日起至2013.10.31截止

    活动地址:http://img.kaba365.com/mail_files/kaba1yuan.html

  8. Ubuntu系统安装,适用于14.04,16.04和17.10

    本文以14.04为案例进行安装,其他版本相关问题会做注解 1.选择要安装的系统语言 本界面建议选择English,之后再选择中文安装 注意: 安装服务器版时,对于14.x版本第一步选择中文没有问题,但 ...

  9. 51Nod 1049:最大子段和(dp)

    1049 最大子段和  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 N个整数组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+ ...

  10. Python 使用Microsoft SQL Server数据库

    软件环境: Windows 7 32bit Python 3.6  Download https://www.python.org/downloads/ 默认安装,并添加环境变量,一路Next ... ...