java cxf 3.1.6搭建web_Spring4.X集成CXF3.1.7 WebService框架

开发环境说明:

操作系统:Windows7_x64

JDK版本:jdk1.8.0_101

Eclipse版本:Mars.2 Release (4.5.2)

Web服务器:Tomcat7.X

Spring版本:spring-framework-4.2.5.RELEASE

CXF版本:CXF3.1.7

Eclispe工程项目:

1、新建一个Eclipse的WEB工程

1476114074890099290.png

引入了Spring4和CXF3的所有jar包,也可以选择必须的JAR包即可。

2、IWhat21Hello.java源码package com.what21.cxf3;

import javax.jws.WebMethod;

import javax.jws.WebParam;

import javax.jws.WebService;

import javax.xml.ws.BindingType;

import javax.xml.ws.soap.SOAPBinding;

@WebService

@BindingType(value = SOAPBinding.SOAP12HTTP_BINDING)

public interface IWhat21Hello {

/**

* WebService服务的方法

*/

@WebMethod

public String sayHi(@WebParam(name="text")String text);

}

3、What21HelloImpl.java源码package com.what21.cxf3;

import javax.jws.WebService;

@WebService(endpointInterface = "com.what21.cxf3.IWhat21Hello",

serviceName = "What21Hello")

public class What21HelloImpl implements IWhat21Hello {

@Override

public String sayHi(String text) {

System.out.println("请求的内容 -> " + text);

return text;

}

}

4、web.xml配置<?xml  version="1.0" encoding="UTF-8"?>

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

id="WebApp_ID" version="3.0">

0300_CXF3

contextConfigLocation

classpath:applicationContext-*.xml

org.springframework.web.context.ContextLoaderListener

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

1

CXFServlet

/webservice/*

index.jsp

注意这里的路径:url-pattern配置的内容和CXF配置的服务路径为WSDL的URL。

5、applicationContext-cxf.xml配置<?xml  version="1.0" encoding="UTF-8"?>

xmlns:context="http://www.springframework.org/schema/context"

xmlns:jaxws="http://cxf.apache.org/jaxws"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-4.0.xsd

http://cxf.apache.org/jaxws

http://cxf.apache.org/schemas/jaxws.xsd">

implementor="#what21Hello" address="/what21Hello">

启动tomcat7后的WSDL访问地址:http://127.0.0.1:8080/CXF3/webservice/what21Hello?wsdl,使用SOAPUI导入WSDL地址测试后,服务调用成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值