关于apache-cxf就不多说了。百度看下吧。
由于我是用maven管理的,需要的几个核jar包是:
[html]
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>${apache.cxf}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${apache.cxf}</version>
</dependency>
<!--启动Server时遇到Could not find destination factory for transport http://schemas.xmlsoap.org/soap/http错误 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${apache.cxf}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-api</artifactId>
<version>${apache.cxf}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${apache.cxf}</version>
</dependency>
<!--启动Server时遇到Could not find destination factory for transport http://schemas.xmlsoap.org/soap/http错误 -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${apache.cxf}</version>
</dependency>
写个简单的helloword吧。
整体目录结构如下:
和之前一样,先编写服务端代码:
[java]
package com.whaty.test.ws.cxf.service;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
* @name:HelloWorldService.java
* @desc:
* @author:lizhuang
* @createTime:2012-12-28 下午04:37:28
*/
@WebService
public class HelloWorldService {
//@WebParam(name = "name")意思是指定参数的名称为name,否则默认为arg0,arg1.....
public String sayHello(@WebParam(name = "name") String name) {
System.out.println("~~~~~~~~~~~~~~~~");
return name + " say: Hello World ";
}
}
package com.whaty.test.ws.cxf.service;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
* @name:HelloWorldService.java
* @desc:
* @author:lizhuang
* @createTime:2012-12-28 下午04:37:28
*/
@WebService
public class HelloWorldService {
//@WebParam(name = "name")意思是指定参数的名称为name,否则默认为arg0,arg1.....
public String sayHello(@WebParam(name = "name") String name) {
System.out.println("~~~~~~~~~~~~~~~~");
return name + " say: Hello World ";
}
}
服务端接写好之后,我们先发布看一下有没有问题:
[java]
package com.whaty.test.ws.cxf.service.deploy;
import javax.xml.ws.Endpoint;
import com.whaty.test.ws.cxf.service.HelloWorldService;
/**
* @name:DeployHelloWorldService.java
* @desc:
* @author:lizhuang
* @createTime:2012-12-28 下午04:39:45
*/
public class DeployHelloWorldService {
public static void deployService() {
System.out.println("Server start ……");
HelloWorldService service = new HelloWorldService();
String address = "http://localhost:9000/helloWorld";
Endpoint.publish(address, service);
}
public static void main(String[] args) throws InterruptedException {
// 发布WebService
deployService();
System.out.println("server ready ……");
//Thread.sleep(1000 * 300);
//System.out.println("server exiting");
// 休眠300秒后就退出
//System.exit(0);
}
}
package com.whaty.test.ws.cxf.service.deploy;
import javax.xml.ws.Endpoint;
import com.whaty.test.ws.cxf.service.HelloWorldService;
/**
* @name:DeployHelloWorldService.java
* @desc:
* @author:lizhuang
* @createTime:2012-12-28 下午04:39:45
*/
public class DeployHelloWorldService {
public static void deployService() {
System.out.println("Server start ……");
HelloWorldService service = new HelloWorldService();
String address = "http://localhost:9000/helloWorld";
Endpoint.publish(address, service);
}
public static void main(String[] args) throws InterruptedException {
// 发布WebService
deployService();
System.out.println("server ready ……");
//Thread.sleep(1000 * 300);
//System.out.println("server exiting");
// 休眠300秒后就退出
//System.exit(0);
}
}
右键运行发布,如果出现server ready应该就没有什么问题了。
注意:和之前的不同,这里的cxf服务端不是写的接口,也没有所谓的实现类和
补充:Web开发 , 其他 ,