使用cxf发布WebService(Spring)
来源:互联网 发布:杂志制作软件 编辑:程序博客网 时间:2024/06/06 00:18
这篇文章介绍一下如何在java中发布WEB SERVICE
在java程序发布web serice 可以使用几种开源的产品如:
AXIS,XFIRE,CXF。现在CXF应该可以取代XFIRE作为首选的WEB SERVICE 发布产品。
下面介绍一下如何使用CXF发布一个web service。
1.下载CXF。
在 http://cxf.apache.org/ 下载cxf软件。
2.新建一个web项目。
添加如下包的引用。
commons-logging-1.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar
spring 的包
aopalliance-1.0.jar
spring-core-2.0.8.jar
spring-beans-2.0.8.jar
spring-context-2.0.8.jar
spring-web-2.0.8.jar
cxf 的包
cxf-2.1.jar
geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar)
geronimo-annotation_1.0_spec-1.1.jar (JSR 250)
geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar)
geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar)
geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181)
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
neethi-2.0.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
XmlSchema-1.2.jar
xml-resolver-1.2.jar
spring 的包
aopalliance-1.0.jar
spring-core-2.0.8.jar
spring-beans-2.0.8.jar
spring-context-2.0.8.jar
spring-web-2.0.8.jar
cxf 的包
cxf-2.1.jar
这个包可能跟使用的cxf版本有差异。
修改 web.xml
按 Ctrl+C 复制代码
按 Ctrl+C 复制代码
3.编写webservice。
开发一个web服务接口。接口代码如下:
package com.gzepb.motor;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService(targetNamespace="http://www.xxx.com/")
public interface IServer {
public String hello(@WebParam(name="name") String name);
}
imp
imp
@WebService(targetNamespace="http://www.xxx.com/")
public interface IServer {
public String hello(@WebParam(name="name") String name);
}
实现类如下:
package com.gzepb.motor.impl;
import com.gzepb.motor.IServer;
public class ServiceImpl implements IServer {
public String hello(String name) {
// TODO Auto-generated method stub
return "hello :" + name;
}
}
imp
public class ServiceImpl implements IServer {
public String hello(String name) {
// TODO Auto-generated method stub
return "hello :" + name;
}
}
下面的工作就是配置这个web service了
<?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-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- Import Apache CXF Bean Definition -->
<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"/>
<!-- gzepbmotorService -->
<bean id="ServerImpl" class="com.gzepb.motor.impl.ServiceImpl">
</bean>
<!-- Expose SurveyWebService -->
<jaxws:server id="motorService"
serviceClass="com.gzepb.motor.IServer"
address="/motorService">
<jaxws:serviceBean>
<ref bean="ServerImpl"/> <!-- 要暴露的 bean 的引用 -->
</jaxws:serviceBean>
</jaxws:server>
</beans>
<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-2.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- Imp
<imp
<imp
<imp
<!-- gzepbmotorService -->
<bean id="ServerImpl" class="com.gzepb.motor.impl.ServiceImpl">
</bean>
<!-- Expose SurveyWebService -->
<jaxws:server id="motorService"
serviceClass="com.gzepb.motor.IServer"
address="/motorService">
<jaxws:serviceBean>
<ref bean="ServerImpl"/> <!-- 要暴露的 bean 的引用 -->
</jaxws:serviceBean>
</jaxws:server>
</beans>
0 0
- 使用cxf发布WebService(Spring)
- 使用CXF发布和调用webService(不使用Spring)
- 使用Spring + CXF 发布WebService服务
- cxf+spring发布webservice
- cxf+spring发布webservice
- spring +cxf 发布webservice
- spring+cxf发布webservice
- CXF+Spring发布webservice
- 使用CXF发布webService
- 使用CXF发布WebService
- webService总结(一)——使用CXF发布和调用webService(不使用Spring)
- webService总结(二)——使用CXF手动发布webService(不使用Spring)
- webService总结(三)——使用CXF + Spring发布webService
- cxf+spring完成webservice发布
- Spring整合CXF发布WebService
- Spring 集合cxf发布webservice
- spring集成cxf发布webservice
- cxf整合spring发布webservice
- C# XmlReader 处理XML文档
- android 3G功能移植
- ab简单的集群压力测试验证
- 模板管理 编辑文件功能
- android 数据传递详解(Serialization、Parcelable、Parcel、Intent等)
- 使用cxf发布WebService(Spring)
- 幂方分解
- STL泛型编程(2)——string
- C#获得反射类属性;获取时间段内,选中的星期(可以多个)匹配的天数
- MFC Attach()函数和Detach()函数 .
- xfire客户端调用
- 乘法口诀表(九九表)
- 搜索--字符串对比
- 第四周 统计工资数目