spring 3.0 cxf2.7.2整合
1,拷贝spring的 jar
2,拷贝cxf的jar包
jetty不需要了
asm
common-logging
neethi
wsdl4j
xmlschema
cxf
http-*
3,修改web.xml 添加对spring的支持
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INFO/applicationContext.xml</param-value>
</context-param>
<listener-class>
ContentLoadListener
</listener-class>
4,在web.xml添加对cxf的支持
//配置cxf的核心控制器
<servlet>
<servlet-name>cxf
<servlet-class>CXFServlet
</servlet>
//所有来自/ws/*的请求交给cxf处理
<servlet-mapping>
<servlet-name>cxf
<url-pattern>/ws/*
</servlet-mapping>
5,在spring中倒入schema和xml配置
在cxf.jar/schema中可以看到 jaxws.xsd 找到命名空间
在cxf.jar/META-INF/spring.schemas 找到schema-location
http\://cxf.apache.org/schemas/jaxws.xsd=schemas/jaxws.xsd
在cxf.jar/META-INF/这里存在一些xml配置文件
在spring需要导入一些配置文件
<import resourse="classpath:/META-INF/xxx.xml"/>
cxf.xml
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
web应用的类加载路径有两类:
1,WEB-INF/classes目录
2,WEB-INF/lib目录
6,在spring中使用jaxws:endpoint元素来暴露Web Service
implementor指定web service的服务提供者,支持两种形式:
1,直接给服务器提供类名
2,设置为spring容器中的一个bean
<jaxws:endpoint
implementor="xxx.xx.xx.Xxx"
address="/ws" >
</jaxws:endpoint>
第二种方式
<bean id="webServiceName" class="xxx.xx.xx.Xxx" >
<ref bean="customerService" />
</bean>
<jaxws:endpoint
implementor="#webServiceName" #代表使用spring容器中的类
address="/ws" >
<jaxws:inInterceptors>
<bean class="xx.xx.xx.Xxx"/>
<bean class="xx.xx.xx.Xxx"/>
</jaxws:inInterceptors>
</jaxws:endpoint>
cxf和Spring的另外一种整合:在action调用web service
1,复制cxf jar包
2,在spring中配置导入cxf提供的schema,xml配置文件(jaxws)
3,在spring中使用jaxws:client来配置webservice
<jaxws:client id="hw"
serviceClass=""
address="http://localhost:8080/ws_03_server_cxf_spring3.1/ws?wsdl">
<jaxws:outInterceptors>
<bean class="">
<contractor-arg value="admin" />
<contractor-arg value="admin" />
</bean>
</jaxws:outInterceptors>
</jaxws:client>
4,添加拦截器方法一样
服务器端
web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.0"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
- <display-name></display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext.xml</param-value>
- </context-param>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <servlet>
- <servlet-name>CXF</servlet-name>
- <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
- </servlet>
- <!-- 所有来自/ws/*的请求交给cxf处理 -->
- <servlet-mapping>
- <servlet-name>CXF</servlet-name>
- <url-pattern>/ws/*</url-pattern>
- </servlet-mapping>
- </web-app>
spring配置applicationContext.xml
- <?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:oxm="http://www.springframework.org/schema/oxm"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/oxm
- http://www.springframework.org/schema/oxm/spring-oxm-3.0.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
- implementor="com.kenan.cxf.ws.impl.HelloWorldImpl"
- address="/ws" >
- </jaxws:endpoint> -->
- <!-- 第二种方式 -->
- <bean id="webServiceName" class="com.kenan.cxf.ws.impl.HelloWorldImpl" >
- </bean>
- <!-- #代表使用spring容器中的类 -->
- <jaxws:endpoint
- implementor="#webServiceName"
- address="/ws" >
- <jaxws:inInterceptors>
- <bean class="com.kenan.cxf.auth.AuthInterceptor"/>
- </jaxws:inInterceptors>
- </jaxws:endpoint>
- </beans>
spring客户端
applicationContext.xml
- <?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:oxm="http://www.springframework.org/schema/oxm"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/oxm
- http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
- http://cxf.apache.org/jaxws
- http://cxf.apache.org/schemas/jaxws.xsd">
- <jaxws:client id="hw"
- serviceClass="com.kenan.cxf.ws.HelloWorld"
- address="http://localhost:8080/ws_03_server_cxf_spring3.1/ws/ws?wsdl">
- <jaxws:outInterceptors>
- <bean class="com.kenan.cxf.auth.AuthOutInterceptor">
- <constructor-arg value="admin" />
- <constructor-arg value="admin" />
- </bean>
- </jaxws:outInterceptors>
- </jaxws:client>
- </beans>
测试
- package test;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXmlApplicationContext;
- import com.kenan.cxf.ws.HelloWorld;
- import com.kenan.cxf.ws.impl.HelloWorldImpl;
- import com.sun.security.ntlm.Client;
- public class Test {
- /**
- * @param args
- */
- public static void main(String[] args) {
- ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
- HelloWorld hello = context.getBean("hw", HelloWorld.class);
- // HelloWorldImpl helloWorld = new HelloWorldImpl();
- // com.kenan.cxf.ws.HelloWorld hello = helloWorld.getHelloWorldImplPort();
- //拦截器
- // Client client = ClientProxy.getClient(hello);
- // client.getOutInterceptors().add(new AuthOutInterceptor("admin", "admin"));
- // client.getOutInterceptors().add(new LoggingOutInterceptor());
- hello.hello("你好");
- // User user = new User();
- // user.setName("柯南");
- // List<Cat> l = hello.getCatsByUser(user);
- // for(Cat cat:l){
- // System.out.println(cat.getName());
- // }
- // StringCat s = hello.getAllCats();
- // for(Entry entry:s.getEntries()){
- // System.out.println(entry.getKey()+":"+entry.getValue());
- // }
- }
- }
相关推荐
**标题:“CXF和Spring整合,并且添加拦截器”** 在Java世界中,Apache CXF是一个流行的开源服务框架,用于创建和消费Web服务。它支持多种Web服务规范,包括SOAP、RESTful API以及WS-*标准。另一方面,Spring框架是...
这里我们将深入探讨CXF与Spring整合时所需的jar包及其作用。 首先,我们需要理解整合的目的:通过Spring管理CXF的服务生命周期,使得服务的创建、配置和管理更加便捷。为了实现这一目标,我们需要以下关键的jar包:...
将CXF与Spring整合的主要好处在于,可以利用Spring的强大管理和配置能力来管理CXF服务。Spring的DI可以帮助我们将CXF的服务bean与其他业务逻辑bean解耦,从而提高代码的可测试性和可维护性。此外,Spring还提供了对...
**标题解析:** "CXF和Spring整合开发的服务端及客户端" 指的是使用Apache CXF框架与Spring框架相结合,构建服务端(服务提供者)和服务端客户端(服务消费者)。CXF是一个开源的Web服务框架,它允许开发者创建和...
"CXF+Spring整合"是企业级Java应用程序中常用的一种技术组合,它结合了Apache CXF(一个用于构建和服务导向架构的开源框架)和Spring框架的优势,以实现高效、灵活的服务开发和管理。在Java世界里,CXF常用于创建Web...
将CXF与Spring整合的主要目的是利用Spring的管理能力来配置和控制CXF组件,例如服务端点、客户端代理等。这样可以实现更细粒度的控制,提高代码的可测试性和可维护性。 整合步骤如下: 1. **引入依赖**:首先,在...
将CXF与Spring整合,可以充分利用Spring的管理能力,简化服务的创建和维护。 1. **整合步骤** - **配置Spring**:首先,我们需要在Spring配置文件中定义CXF的相关bean,如服务接口的实现类、服务端点、服务发布器...
在企业级应用开发中,Apache CXF 和 Spring 框架的整合是非常常见的,因为它们分别提供了强大的服务端和客户端的 Web 服务支持以及灵活的依赖注入和配置管理。本教程将详细介绍如何将 CXF 与 Spring 整合,帮助...
解压这个"spring-cxf"压缩包后,你会找到一系列的JAR文件,这些文件包含了CXF和Spring整合所需的类和库。例如,可能包含的有: 1. `cxf-api.jar`:CXF的核心API,包含了服务接口和数据绑定相关的类。 2. `cxf-rt-...
当我们需要在CXF和Spring整合的基础上发布Web服务,并对权限进行控制时,可以利用拦截器来实现这一目标。本文将详细介绍如何为CXF与Spring整合发布WebService添加拦截器进行权限控制。 首先,我们需要理解CXF拦截器...
**标题解析:** "cxf与Spring的整合实例(适合初学者)" 指的是一个教程或示例项目,旨在帮助初次接触CXF和Spring框架的开发者理解如何将这两个强大的开源工具集成在一起。CXF是一个流行的开源服务框架,常用于构建...
标题"webservice(cxf)与spring整合源码+文档"表明这是一个关于如何将CXF Web服务与Spring框架集成的学习资源。文档和源代码一起提供,使得学习者能够通过实践来理解这一过程。 描述中提到"webservice与spring整合...
在【压缩包子文件的文件名称列表】中,"cxf-spring"可能包含的是用于集成CXF与Spring的必要jar包,如cxf-spring-integration.jar,这个文件通常包含了CXF与Spring集成所需的类和资源,使得开发者能够在Spring环境下...
5. **Spring整合CXF**:Spring可以通过`cxf-spring`模块来集成CXF,通过`<jaxws:endpoint>`或`<jaxrs:server>`标签在Spring配置文件中声明Web服务。这样,Spring容器会管理Web服务的生命周期,服务实例可以在需要时...
2. **CXF的Spring支持**:CXF提供了对Spring的深度集成,可以通过Spring的XML配置或注解来定义和管理Web服务。例如,使用`<jaxws:endpoint>`标签创建一个基于JAX-WS的服务端点,或者使用`<jaxrs:server>`创建基于JAX...
这篇博客文章可能是一个简单的教程,教你如何将Apache CXF和Spring整合在一起,创建一个基本的服务端点。 在整合Apache CXF和Spring时,首先需要在Spring配置文件中声明CXF的相关bean。这通常包括服务接口、服务...
cxf-2.2.9.jar geronimo-javamail_1.4_spec-1.7.1.jar geronimo-jaxws_2.2_spec-1.1.jar geronimo-jms_1.1_spec-1.1.1.jar geronimo-servlet_3.0_spec-1.0.jar jaxb-api-2.2.6.jar jaxb-impl-2.2.6.jar neethi-3.0.1...