1.首先你需要创建一个maven项目【当然是web项目】

2.pom.xml添加以下

<properties>
  <cxf.version>2.2.3</cxf.version>
</properties>

<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-frontend-jaxws</artifactId>
  <version>${cxf.version}</version>
</dependency>
<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-transports-http</artifactId>
  <version>${cxf.version}</version>
</dependency>

没错只需要引入这两个,然后cxf需要的其他jar也会自动添加到项目中。

3.在项目的web.xml中添加

<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>/cxf/*</url-pattern>
</servlet-mapping>

4.具体代码的实现如下:

4.1写一个接口IHelloService.java

package com.niuniu.service;

import javax.jws.WebService;

@WebService
public interface IHelloService {
  public String wolaile(String userName);
}

4.2写接口的实现HelloServiceImpl.java

package com.niuniu.service.impl;

import javax.jws.WebService;

import org.springframework.stereotype.Component;
import com.niuniu.service.IHelloService;

@WebService(endpointInterface="com.niuniu.service.IHelloService",serviceName="helloService")
@Component
public class HelloServiceImpl implements IHelloService {

  @Override
  public String wolaile(String userName) {

    return "Hello, wolaile, " + userName;
  }

}

4.3配置文件如下:

<?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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint id="helloService" implementor="com.niuniu.service.impl.HelloServiceImpl"  address="/cxfService" />
</beans>

spring的相关配置就不在这里叙述了。

【如果没有搭过spring的web项目的,可以先搜索一个能跑起来的web项目,然后把这些配置放到能跑起来的项目中就可以了】

把项目发布到tomcat上,然后访问http://localhost:8080/ownweb/cxf/cxfService?wsdl,看下能否成功访问。

【ownweb是你的项目名,cxf是在web.xml中配置的<url-pattern>,cxfService是4.3中address的值,根据自己的需要可以修改下】

最新文章

  1. 建站技能get(1)— Asp.net MVC快速集成ckplayer网页视频播放器
  2. linux下使用taskset设置进程cpu绑定不起作用
  3. SqlServer 18456 错误解决方案
  4. 配置了&lt;mvc:resources&gt; 导致以前的controller 无法访问。
  5. TCP/IP详解 学习二
  6. ArcGIS Engine中加载数据
  7. CREATEINPUTLAYOUT_INCOMPATIBLEFORMAT
  8. shell下,进程的前台与后台运行
  9. 【Mongo】Linux安装MongoDB
  10. [转] splice系列系统调用
  11. Log4net配置与使用简要说明
  12. 详解URL的组成
  13. Android破解——支付宝内购破解方法总结
  14. ASP.NET MVC WebAPI Put和Delete请求出现405(Method not allowed)错误
  15. Sonar+maven+jenkins集成,Java代码走查
  16. GlusterFS分布式存储系统中更换故障Brick的操作记录1
  17. VS2012创建ATL工程及使用MFC测试COM组件
  18. 【mysql】IP地址整数int和varchar的转换
  19. EVIL TWIN AP
  20. HTTP/1.1新建会话失败 解决方法及分析

热门文章

  1. 基于Tensorflow + Opencv 实现CNN自定义图像分类
  2. CS:APP Chapter 3 程序的机器级表示-读书笔记
  3. symfony的几个请求变量和方法
  4. 深入HTML5第三天
  5. pycharm 增删改查 mysql数据库
  6. Github新手入门
  7. 软件开发的V模型
  8. prometheus+grafana实现服务监控
  9. Windows下Vim插件管理器Vundle的安装以及使用简介
  10. NOIP模拟66