准备工作:
下载spring,apache-cxf,soapUI
新建Web项目
接口
package com.gary.test.ws.service;
import javax.jws.WebService;
@WebService
public interface GreetingService {
public String greeting(String userName);
}
实现
package com.gary.test.ws.service.impl;
import java.util.Calendar;
import javax.jws.WebService;
import com.gary.test.ws.service.GreetingService;
@WebService(endpointInterface = "com.gary.test.ws.service.GreetingService")
public class GreetingServiceImpl implements GreetingService {
public String greeting(String userName){
return "Hello " + userName + ", currentTime is " + Calendar.getInstance().getTime();
}
}
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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="greetingService"
implementor="com.gary.test.ws.service.impl.GreetingServiceImpl"
address="/GreetingService" />
</beans>
web.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<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>/*</url-pattern>
</servlet-mapping>
</web-app>
到此代码部分结束,所需jar包列表
部署到tomcat,项目启动后可以看到
安装soapUI,打开soapUI,new soapUI Project,如下,WSDL写之前配置的地址http://gary-pc:8080/testWebService/GreetingService?wsdl
,OK
添加参数arg0的值,submit,可以看到右侧的返回结果
OK测试通过,成功返回正确结果
不用soapUI的话也可以直接写测试类
package com.gary.test.ws.test;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.gary.test.ws.service.GreetingService;
public class TestGreetingService {
public static void main(String[] args) {
//创建WebService客户端代理工厂
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
//注册WebService接口
factory.setServiceClass(GreetingService.class);
//设置WebService地址
factory.setAddress("http://gary-pc:8080/testWebService/GreetingService");
GreetingService greetingService = (GreetingService)factory.create();
System.out.println("invoke webservice...");
System.out.println("message context is:"+greetingService.greeting("gary"));
}
}
- 大小: 32.9 KB
- 大小: 66.2 KB
- 大小: 70.8 KB
- 大小: 194.7 KB
分享到:
相关推荐
本java工程实现了spring+cxf快速开发webservice jar包齐全导入myeclipse可直接二次开发
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
Spring+CXF开发WebService源代码,包括所需要的基本jar,调试通过,适合初学者入门学习。
Spring + cxf = webservice 完整实例源码免费下载 完全免费。此资源仅为文档提供。 版权为百度文档 "Spring + cxf = webservice 完整实例源码免费下载" 所有。
Web项目中基于Maven与Spring整合的WebService之cxf的实现⬇️ 详情请参考如下链接: https://locqi.github.io/locqi.com/2018/09/05/Eclipse+Maven+Spring+CXF-create-WebService/
Spring+CXF 发布WebService服务
mybatis+spring+cxf webservice服务 项目框架代码例子,绝对是可以参考的,信不信,只有下载之后才知道
利用spring+cxf轻松实现webservice接口
maven+spring+cxf 的webservice开发源码,欢迎大家指点,谢谢
Spring+CXF实现WebService,包含了服务端和客户端的代码。
cxf+spring+tomat开发webservice所需jar包,该jar包只需解压后导入web工程即可,亲测有用
ibatis+spring+cxf+mysql搭建webservice的客户端,文章地址在http://blog.csdn.net/cenyi2013/article/details/17315755. 服务端源码的下载地址在http://download.csdn.net/detail/cenyi2012/6712729
Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services 各种类型的Annotation。@WebService和@WebMethod是WSDL映射Annatotion。这些Annotation将描述Web ...
第一天: 什么是webservice? 从案例(便民查询网站)分析如何实现?...CXF开发webservice: CXF入门程序 Spring+cxf整合(重点) CXF发布rest的webservice。(重点) 综合案例: 实现便民查询网站
SpringBoot+Mybatis+CXF框架,实现Restful api与 WebService api接口的大实验
jar包1 为Spring+cxf=webservice 提供 http://download.csdn.net/detail/sys01752/3850680 需要本jar包才能运行
采用spring4.1+mybatis+cxf搭建的webservice demo
WebService—CXF发布服务spring+cxf的doc文档,以及apache-cxf用到的的jar包
调用webservice,插入数据,整合druid监控数据源;... webservice配置文件在spring-mvc.xml和web.xml中; 数据库监控地址http://localhost:8080/taixingMsg/druid/index.html... 各位同仁,生命不止,奋斗不息