(三)HelloWorld
准备工作
eclipse 3.6
tomcat 6
jdk 1.7
cxf 相关架包,spring相关架包,jdbc相关架包
创建一个工程,把架包添加到lib中
写一个接口
package com.cxf.test; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface HelloWorld { String zhuce(String username, String password); }
写一个实现
package com.cxf.test; import javax.jws.WebService; /** * @ WebService:申明为webservice的注解 * endpointInterface:要暴露的接口类 * serviceName : 服务名 */ @WebService(endpointInterface ="com.cxf.test.HelloWorld", serviceName = "HelloWorld") public class HelloWorldImpl implements HelloWorld { public String zhuce(String username, String password) { String result = ""; if(username.equals("admin")){ result = "用户名已经存在"; } else if (password.length() != 6) { result = "请输入6位数密码"; } return result; } }
发布web service
package com.cxf.test; import javax.xml.ws.Endpoint; import org.apache.cxf.jaxws.JaxWsServerFactoryBean; public class service { public static void startService() throws Exception{ //通过CXF内置的Jetty应用服务器发布 //方法1:用CXF的JaxWsServerFactoryBean类进行发布。(需要CXF相关包) HelloWorldImpl hw = new HelloWorldImpl(); JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean(); factoryBean.setAddress("http://localhost:8080/cxf/HelloWorld"); factoryBean.setServiceClass(HelloWorld.class); factoryBean.setServiceBean(hw); factoryBean.create(); System.out.println("方法1"); //方法2:使用Sun JAX-WS 2中Endpoint.publish进行发布 /*Endpoint endpoint = Endpoint.publish("http://localhost:10080/cxf/HelloWorld", new HelloWorldImpl()); System.out.println("方法2");*/ } public static void main(String[] args) throws Exception{ startService(); System.out.println("Web Service 发布成功"); } }
在浏览器里面输入http://localhost:10080/cxf/HelloWorld?wsdl,就可以看见XML文件了,控制台打印 发布成功.
相关推荐
利用CXF3.0+Spring3.2 HelloWorld实例,并且导入了小量的jar包以及在写例子的过程中遇见的一些错误!
cxf2.1.3 web项目Helloworld,在tomcat6.0可以跑,相关lib可以从cxf.apache.org下载.
cxf+spring+tomcat 只是演示,一个helloWorld的例子
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
Spring+CXF+MyBatis整合代码,运行即可使用。
cxf+spring+client+springmvc
cxf+spring实现webservice
CXF+spring+struts实现WebService
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
用CXF+Eclipse开发Web Services程序,包括环境搭建,插件安装以及简单的Web Services入门程序。
CXF+Spring+Tomcat发布WebService
SpringBoot+mybatis+CXF开发web service接口,数据库用的是mysql,表结构在图片中,附上的还有自动生成的客户端代码
这个是cxf+spring发布webservice和restservice的服务端项目
代码是我一行行敲的,直接部署就能用,service,client端实现了:(cxf用的是3.0最新的) 1维数组, 2维数组, 3维数组, List, List , Map(adapter方式实现的), 直接返回bean, 返回object[], 做了header的安全认证校验.
CXF+Spring+MyBatis+Maven项目整合,包含服务端和客户端。
这个是cxf 集成spring 的webservice的例子 供大家参考
CXF+spring+restful创建一个web的接口项目源代码,添加了restful实现的配置及jar包
1):含有spring-3.2.8.RELEASE.jar、velocity-tools-2.0.jar、velocity-1.7.jar、mybatis-spring-1.0.2.jar、mybatis-3.0.6.jar、cxf-api-2.2.9.jar等丰富的jar包。 2):采用spring3.2作为bean容器管理,...
CXF+Jetty发布WebService
内容为CXF整合spring的服务端和客户端开发例子,注释不太详尽,网上的教程比较多,但是多跑不起来,特地把整个工程都打包给大家做参考,程序内容均来自网上整理,均可以运行。