现在使用的最流行的webservice框架基本上就是Axis,Axis2和Cxf,其实这些框架间这有各的特点,并不能一概而论哪个好,哪个不好,关键是要根据你的系统自身去选择,看哪个更适合于你。
以下是Axis2和Cxf的部分比较:
1.CXF支持WS-Addressing,WS-Policy,WS-RM,WS-Security 和 WS-I 基本规范。Axis2支持除WS-Policy之外的所有协议,WS-Policy也会在即将到来的版本支持。
2.CXF很容易和Spring集成,而Axis2不。
3.Axis2
支持范围更大的数据绑定,包括XMLBeans、JiBX、JaxMe和JaxBRI同时还有它自带的数据绑定方式--ADB。注意对JaxME和
JaxBRI的支持在Axis2
1.2中仍然处在实验阶段。CXF目前仅支持JAXB和Aegis,对XMLBeans、JiBX和Castor的支持将会在CXF 1.2中实现。
4.Axsi2支持多种语言--在java版本之外还有C/C++的版本可用。
5.Axis2有利于web services的独立,不依赖其他应用,Cxf可以更好的嵌入到原有系统中,专注于开发者的高效和可嵌入性。
服务器端:
导入包(jaxws-api-2.0.jar在服务器端不是必须的):
aopalliance-1.0.jar
commons-logging-1.1.jar
cxf-2.0.2-incubator.jar
geronimo-activation_1.1_spec-1.0-M1.jar
geronimo-annotation_1.0_spec-1.1.jar
geronimo-javamail_1.4_spec-1.0-M1.jar
geronimo-servlet_2.5_spec-1.1-M1.jar
geronimo-ws-metadata_2.0_spec-1.1.1.jar
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxws-api-2.0.jar
neethi-2.0.2.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-core-2.0.4.jar
spring-web-2.0.4.jar
stax-api-1.0.1.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.1.jar
xml-resolver-1.2.jar
XmlSchema-1.2.jar
新建一个web工程cxf,分别编写接口HelloWorld和其实现类HelloWorldImpl,接口暴露出方法sayHello()供客户端调用(注,必须使用jdk1.5进行编译):
HelloWorld:
-
package
cn.com.service;
-
-
import
javax.jws.WebService;
-
-
@WebService
-
public
interface
HelloWorld {
-
-
public
String sayHello(String text);
-
}
package cn.com.service;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public String sayHello(String text);
}
HelloWorldImpl:
-
package
cn.com.service;
-
-
import
javax.jws.WebService;
-
-
@WebService
(endpointInterface=
"cn.com.service.HelloWorld"
)
-
public
class
HelloWorldImpl
implements
HelloWorld {
-
-
public
String sayHello(String text) {
-
-
return
"Hello"
+ text ;
-
}
-
-
}
package cn.com.service;
import javax.jws.WebService;
@WebService(endpointInterface="cn.com.service.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String text) {
return "Hello" + text ;
}
}
在spring的配置文件spring-bean.xml中配置:
-
<
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.xsd
-
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
-
-
<
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"
/>
-
-
<
bean
id
=
"hello"
class
=
"cn.com.service.HelloWorldImpl"
/>
-
-
<
jaxws:endpoint
id
=
"helloWorld"
implementor
=
"#hello"
-
address
=
"/HelloWorld"
/>
-
-
-
</
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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<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" />
<bean id="hello" class="cn.com.service.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello"
address="/HelloWorld" />
</beans>
web.xml:
-
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
-
<
web-app
version
=
"2.4"
xmlns
=
"http://java.sun.com/xml/ns/j2ee"
-
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
-
xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee
-
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
-
<
context-param
>
-
<
param-name
>
contextConfigLocation
</
param-name
>
-
<
param-value
>
classpath:spring-bean.xml
</
param-value
>
-
</
context-param
>
-
-
<
listener
>
-
<
listener-class
>
-
org.springframework.web.context.ContextLoaderListener
-
</
listener-class
>
-
</
listener
>
-
-
<
servlet
>
-
<
servlet-name
>
CXFServlet
</
servlet-name
>
-
<
display-name
>
CXF Servlet
</
display-name
>
-
<
servlet-class
>
-
org.apache.cxf.transport.servlet.CXFServlet
-
</
servlet-class
>
-
<
load-on-startup
>
1
</
load-on-startup
>
-
</
servlet
>
-
-
<
servlet-mapping
>
-
<
servlet-name
>
CXFServlet
</
servlet-name
>
-
<
url-pattern
>
/*
</
url-pattern
>
-
</
servlet-mapping
>
-
</
web-app
>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-bean.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
将应用部署到web服务器中(我是部署到tomcat下),可以通过http://localhost:8080/cxf/HelloWorld?wsdl
检测是否发布成功.
客户端:
导入的包同服务器端相同(只是要将服务器端的接口类打成jar包,方便在客户端调用)
client:
-
package
cn.com.client;
-
-
import
org.springframework.context.ApplicationContext;
-
import
org.springframework.context.support.ClassPathXmlApplicationContext;
-
-
import
cn.com.service.HelloWorld;
-
-
public
class
client {
-
-
public
static
void
main(String[] args) {
-
-
ApplicationContext ctx = new
ClassPathXmlApplicationContext(
-
"spring-bean.xml"
);
-
HelloWorld client = (HelloWorld) ctx.getBean("client"
);
-
String result = client.sayHello("你好@@!!"
);
-
System.out.println(result);
-
}
-
}
spring-bean.xml:
-
<
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.xsd
-
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
-
-
<
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"
/>
-
-
<
bean
id
=
"hello"
class
=
"cn.com.service.HelloWorldImpl"
/>
-
-
<
jaxws:endpoint
id
=
"helloWorld"
implementor
=
"#hello"
-
address
=
"/HelloWorld"
/>
-
-
-
</
beans
>
分享到:
相关推荐
Web Service Cxf转换器的示例,包含源码和jar包。
07.处理Map等CXF无法自动转换的复合数据类型的形参和返回值
cxf3.1.7最小包
spring+cxf 入门demo 包括spring配置,web配置,代码实现,简单易懂
cxf 小案例 java webservice
apache-cxf-2.6.1最小依赖包,自测可用,请自行下载。本来想免费分享给各位,但是分数不能标0。另有cxf-2.7.18版本,链接如下:https://download.csdn.net/download/jxsczqh/10814176
CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载 CXF下载
CXF 客户端最少jar包支持,CXF 客户端最少jar包支持,CXF 客户端最少jar包支持,
JAVA7和JAVA8对应CXF资源 WebService CXF 用了一天时间找,官网打不开,国内要积分,下下来又永不了。最后终于搞到手,上传上来分享给大家。 jdk版本 CXF版本 java 9及以上 3.3.x java 8 3.x java 7 2.2x --- ...
CXF源码:CXF_Spring源码 CXF源码:CXF_Spring源码
Spring CXF Restful 实例
apache-cxf-2.7.18最小依赖包,自测可用,请自行下载。
cxf服务端开发
CXF Webservice 开发手册
利用Apache CXF开发webservice接口需要用到的jar集合 cxf-core-3.0.15.jar cxf-rt-bindings-soap-3.0.15.jar cxf-rt-bindings-xml-3.0.15.jar cxf-rt-databinding-jaxb-3.0.15.jar cxf-rt-frontend-jaxws-3.0.15.jar...
Apache CXF是一个开源的Service框架,它实现了JCP与Web Service中一些重要标准。CXF简化了构造,集成,面向服务架构(SOA)业务组件与技术的灵活复用。在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式...
<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"/>
spring 4.2.0 集成的cxf3.1.18的jar包,cxf-core-3.1.18.jar、cxf-rt-bindings-soap-3.1.18.jar、cxf-rt-databinding-jaxb-3.1.18.jar、cxf-rt-frontend-jaxws-3.1.18.jar、cxf-rt-frontend-simple-3.1.18.jar、cxf-...
Apache CXF = Celtix + XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-WS 全面的支持,并且提供了多种 Binding 、...
使用apache cxf开发一个入门小程序