service接口代码:
package com.gary.test.ws.service; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface GreetingService { public String greeting(@WebParam(name="userName") String userName); }
serviceImpl接口实现类代码:
package com.gary.test.ws.service.impl; import java.util.Calendar; 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(); } }
测试代码:
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://localhost:6070/testWebService/GreetingService"); GreetingService greetingService = (GreetingService)factory.create(); System.out.println("invoke webservice..."); System.out.println("message context is:"+greetingService.greeting("gary")); } }
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>
编写完成后,启动tomcat,访问http://localhost:6070/testWebService/GreetingService?wsdl
相关推荐
Web项目中基于Maven与Spring整合的WebService之cxf的实现⬇️ 详情请参考如下链接: https://locqi.github.io/locqi.com/2018/09/05/Eclipse+Maven+Spring+CXF-create-WebService/
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
Spring + cxf = webservice 完整实例源码免费下载 完全免费。此资源仅为文档提供。 版权为百度文档 "Spring + cxf = webservice 完整实例源码免费下载" 所有。
本java工程实现了spring+cxf快速开发webservice jar包齐全导入myeclipse可直接二次开发
利用spring+cxf轻松实现webservice接口
纯java调用ws-security+CXF实现的webservice安全接口
mybatis+spring+cxf webservice服务 项目框架代码例子,绝对是可以参考的,信不信,只有下载之后才知道
maven+spring+cxf 的webservice开发源码,欢迎大家指点,谢谢
SpringBoot+Mybatis+CXF框架,实现Restful api与 WebService api接口的大实验
Spring+CXF 发布WebService服务
最新cxfWebservice服务整合,其中整合的框架有mybatis+srping3+cxf2.6.3大家可以参考一下,绝对可用信不信只有下载,瞧了才知道!
idea+maven+spring+cxf
调用webservice,插入数据,整合druid监控数据源;... webservice配置文件在spring-mvc.xml和web.xml中; 数据库监控地址http://localhost:8080/taixingMsg/druid/index.html... 各位同仁,生命不止,奋斗不息
spring+cxf 整合管理webService,并采用c3p0实现数据库连接;代码简单,适合新手参考。项目导入eclipse后,要想跑通,需更改applicationContext-*.xml和base.properties文件的配置以及几个代码文件。
ibatis+spring+cxf+mysql搭建webservice的客户端,文章地址在http://blog.csdn.net/cenyi2013/article/details/17315755. 服务端源码的下载地址在http://download.csdn.net/detail/cenyi2012/6712729