CXF+Spring实现一个简单WebService
WebService server:
创建一个名为webserviceServer的web项目, 导入相关的jar包和CXF的jar包. CXF可以apache.org去下载.
web.xml
spring-context.xml:
IUserService.java:package com.hao.webservice.client.test;import org.apache.cxf.endpoint.Client;import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;import public class UserServiceTest {public static void main(String[] args) throws Exception {JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); Client client = dcf.createClient("http://localhost:8080/webserviceServer/UserWebService?wsdl"); //login 为接口中定义的方法名称 "chenghao","123456"为传递的2个参数 返回一个Object数组 Object[] objects=client.invoke("login", "chenghao","123456"); System.out.println(objects[0].toString());}}
然后运行UserServiceTest类.