http://cxf.apache.org/download.html
最新版本2.4.1
2.创建一个java工程,将以下jar包复制到工程的classpath下
所有的jar包都可以在${CXF_HOME}\lib目录中找到
3.定义服务接口HelloWorldService
因为这个接口将会被我们暴露为webservice,所以给该接口加一个@WebService标注
- package com.crazycoder2010.webservice.cxf.server;
- import javax.jws.WebParam;
- import javax.jws.WebService;
- /**
- * 服务器端对外提供的服务
- * @author Kevin_Wang03
- *
- */
- @WebService
- public interface HelloWorldService {
- /**
- * 简单的字符串参数
- * @param userName
- * @return
- */
- public String sayHello(@WebParam(name="userName") String userName);
- * 参数为对象的情况
- * @param user
- * @return
- */
- public String sayHelloToUser(User user);
- }
这个实现类实现了我们上面的服务接口,除了要添加@WebService标注外,还要定义该服务的名称serviceName="helloWorldService" 和endpoint(服务接口),其他和普通类没有任何区别
- import javax.jws.WebService;
- * 默认的webservice实现
- *
- * @author Kevin_Wang03
- */
- @WebService(endpointInterface = "com.crazycoder2010.webservice.cxf.server.HelloWorldService", serviceName = "helloWorldService")
- class HelloWorldServiceImpl implements HelloWorldService {
- @Override
- public String sayHello(String userName) {
- System.out.println("HelloWorldServiceImpl.sayHello("+userName+")");
- return "Hello,"+userName;
- }
- public String sayHelloToUser(User user) {
- System.out.println("HelloWorldServiceImpl.sayHelloToUser("+user+")");
- +user.getId()+","+user.getName()+")";
- }