使用apache CXF开发第一个Web服务
Tutorial to develop Contract First webservice using CXF
我们要使用apache CXF完成下面这个Web服务:
|
Tutorial to develop Contract First webservice using CXF
我们要使用apache CXF完成下面这个Web服务:
|
首先创建一个Maven pom.xml如下:
|
在我们的Javaf服务类上加上CXF的元注解 Annotation:
|
使用Maven编译后将产生客户端和服务器端的Web服务代码和配置。
CXF和Spring能够无缝结合在一起(所谓无缝其实也是CXF因为在Spring后面出来,为其做了一个转换,如果CXF
在Spring前面出来,然后不需CXF添加新配置和功能,就和Spring整合在一起,这才叫无侵入性的无缝整合,让
别人为你做特别接口,就是你侵入了别人,大家都依赖JVM才是最大的公平和松耦合和无侵入性)
配置Web.xml如下:
|
在Maven的 projectroot/src/main/resources目录下创建一个Spring的CXF.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" />
<jaxws:endpoint id="EmpWorkHours"
implementor="com.ts.empwork.EmpWorkHoursImpl"
address="/EmpWorkHoursWS">
<jaxws:properties>
</jaxws:properties>
</jaxws:endpoint>
</beans>
部署到Web服务器中,访问 http://localhost:8090/cxfcontractfirstwebapp/services。
个人评价:回想起2006年我们就能够用JBuilder可视化开发工具拖拉一个POJO服务,JBuilder就为我们生成Web服务的配置。
多么简单,敢情开源社区折腾这么多年,添加了apache CXF 以及Spring,和Maven,只是重走了一篇回头路,
好像还没有原来的方便,NetBeans还是提供这个可视化拖拉功能,可惜依赖它的glassfish,再次为JBuilder消失惋惜啊,
用户在工业界和开源社区之间少了一个中间选择。
[该贴被banq于2009-08-30 13:32修改过]