首先 构建环境
1.在eclipse下新建个web项目(我比较喜欢用eclipse),接着添加CXF必须依赖的jar包
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
2.添加spring jar包
aopalliance-1.0.jar
spring-core-2.0.4.jar
spring-beans-2.0.4.jar
spring-context-2.0.4.jar
spring-web-2.0.4.jar
3.构建webservice 本例子是基于jdk1.5 或者更高的版本 通过注解来构建webservice
webservice的接口
package demo.spring;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String sayHi(String text);
}
webservice 的接口实现
package demo.spring;
import javax.jws.WebService;
@WebService(endpointInterface = "demo.spring.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello " + text;
}
}
4 。 spring bean的配置文件
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="demo.spring.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" />
<!-- 另一种写法 是
<jaxws:endpoint id="helloWorld" implementor="demo.spring.HelloWorldImpl" address="/HelloWorld" />
在这里我建议不要用这种方法 ,如果实现类有的属性要通过spring依赖注入的话,这种方法只是简单的new个实现类,他的属性没有通过spring依赖注入给注入值
所有综合考虑 建议使用上面的写法!
-->
</beans>
5. web.xml加载bean.xml文件
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.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>/services/*</url-pattern>
</servlet-mapping>
</web-app>
6.创建客户端配置文件
client-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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
<bean id="client" class="demo.spring.HelloWorld"
factory-bean="clientFactory" factory-method="create"/>
<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="demo.spring.HelloWorld"/>
<property name="address" value="http://localhost:8080/HelloWorld"/>
</bean>
</beans>
7.客户端访问
ApplicationContext context = ...; // your Spring ApplicationContext
HellWorld client = (HelloWorld) context.getBean("client");
OK 。。。其实就是这样的哦。。。。
分享到:
相关推荐
最新版的cxf框架集成了spring包,下载解押后打开eclipse工程右击->build path->add librarys->user library->user librarys->new->自定义包名->选择刚才lib文件路径->ok
在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式(或binding)和网络协议(transports)包括SOAP、XML(通过HTTP或JMS)进行访问。CXF同样支持多种model 如:JAX-WS,JBI,SCA和CORBA service。CXF设计...
源码里面包含了了一个简单的插入功能,主要是为了测试mybatis是否连接上数据库的时候写的测试类,作为一个刚学java,被抓壮丁的写服务器端的妹子,我只想说,画了我3周...如题,基于maven项目的ssm框架和cxf框架的整合。
用于webservice的开发,主要用到spring+cxf的方式实现webservice的发布与简单调用测试,不懂得可以留言给我,比较显新的框架配置,希望你会喜欢!(并包含拦截器的配置!)
Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache CXF 了,以下简称为 CXF。...Spring 进行无缝集成。 想了解新技术的就下下来看看把,应该对你有所帮助。
用webservice中的xfire框架升级到cxf框架开发的实例,供大家分享~~~~
SSM+cxf+log4j整合框架;springmvc+spring+mybatis整合开发,内部集成webservice技术,采用cxf框架进行实现,log4j进行日志记录
服务端ssh框架,apache CXF与Spring集成发布WebService
Apache CXF = Celtix + XFire,Apache CXF 的前身叫 Apache CeltiXfire,现在已经正式更名为 Apache CXF 了,以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-...Spring 进行无缝集成。
Springboot整合cxf测试项目亲测可用,精简版的boot承载cxf框架的资源!
Apache CXF 是一个开源的 Services 框架,CXF 帮助您利用 Frontend 编程 API 来构建和开发 Services ,像 JAX-WS 。这些 Services 可以支持多种协议,比如:SOAP、XML/HTTP、RESTful HTTP 或者 CORBA ,并且可以在...
附件是 WebService 的示例程序(含说明文档) :考虑到 CXF 更容易和 spring 集成,所以WebService 服务端采用了 CXF 框架, 客户端分别用 axis2 和 cxf 两种方式实现 。 框架版本 : CXF:2.3.3 Spring:2.5.6 ...
Maven+Spring+Spring MVC+MyBatis+MySQL整合SSM框架; 已集成activeMq;cxf webservice;邮件;
是一个开源的一个webservice,可以与spring无缝集成。支持soap1.1、1.2、RESTtful或者CORBA。 ##使用CXF实现jax-ws规范的webservice 服务端: 1、创建java工程,把cxf的jar包导入工程中 2、编写SEI,在SEI上添加@...
cxf是用于webservice的开发的框架,可和spring集成开发。
WebService入门案例,使用CXF框架,与Spring进行整合,包括客户端工程和服务端工程。
火龙果软件工程技术中心 在JAXWS2.0发布以前,用JAVA发布一个WebService是一件相当复杂的工作,令很多开发高手都望而却步;...在CXF中,Service使用WSDL标准定义并能够使用各种不同的消息格式(或binding)和网络协议(t
本文总结了当前主流的webservice开发框架的使用方法及说明,以及与spring集成需要注意的事项,共享出来希望对大家有所帮助~
集成Webservice平台,包括jaxws服务、CXF框架,配置双加密的权限认证。使服务集成更加安全。 9. Bootstrap html5提供了两套前台开环境,包括CMS和电子商务网站,使您的开发更加的简洁。 技术点: 1. Springmvc ...