cxf与spring的整合
来源:互联网 发布:mac免费软件推荐 编辑:程序博客网 时间:2024/06/05 19:52
cxf与spring的整合,这里分两部分,分别为server端与client端
server端
1.导入jar包
下载apache-cxf,将其lib目录下的jar导入到项目中的lib中
2.配置web.xml
<!-- 配置beans.xml --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value> </context-param> <!-- 应用启动的一个监听器 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!-- 所有请求都会先经过cxf框架 --> <servlet> <servlet-name>CXFServlet</servlet-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>
3.创建spring的配置文件beans.xml,在其中配置SEI
<?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.xsdhttp://cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd"> <!-- 引入cxf的一些核心配置 --> <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" /> <!-- 配置终端:id-名字,implementor-实现者,address-虚拟地址 --> <jaxws:endpoint id="orderWS" implementor="com.atguigu.day02_ws_cxf_spring.ws.OrderWSImpl" address="/orderws"> </jaxws:endpoint></beans>4.编写服务端接口和实现类
@WebServicepublic interface OrderWS {@WebMethodpublic Order getOrderById(int id);}
@WebServicepublic class OrderWSImpl implements OrderWS {public OrderWSImpl(){System.out.println("OrderWSImpl()");}public Order getOrderById(int id) {System.out.println("server被调用了,id="+id);return new Order(id, "你好", 1000000);}}
client端
1.生成客户端代码
如何生成客户端代码在上一篇已经讲到
2.创建客户端的spring配置文件beans-client.xml
<jaxws:client id="orderClient" serviceClass= "com.atguigu.day02_ws_cxf_spring.ws.OrderWS" address= "http://localhost:8080/day02_ws_cxf_spring/orderws"></jaxws:client>3.测试
public class ClientTest {public static void main(String[] args) {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"client-beans.xml"});OrderWS orderWS = (OrderWS) context.getBean("orderClient");Order order = orderWS.getOrderById(24);System.out.println(order);}}结果为:
1 0
- spring与cxf的整合
- CXF与Spring的整合
- cxf与spring的整合
- spring与cxf的整合
- cxf 与 spring整合
- CXF与Spring整合
- Spring与CXF整合
- Spring与CXF整合
- cxf与spring整合
- cxf与spring的整合使用
- WebService之CXF与Spring的整合
- 详解CXF与Spring的整合
- CXF与Spring框架的整合
- 笔记:CXF与spring整合
- webservice-cxf-与spring整合
- WebService -Spring与CXF整合
- CXF与SPRING的无缝整合时,为什么不用写CXF的配置文件cxf-servlet.xml?
- Spring对CXF的整合
- C语言编程入门——循环(下)
- 免输密码的登录功能的实现——MD5加盐
- POI-----POI操作Excel-1、工作簿
- ubuntu系统小白问题
- 你的UML第一张图是用例图么?(2)——从活动图到用例图
- cxf与spring的整合
- UIApplication sharedApplication详细解释-IOS
- iOS 常量和全局变量的定义
- 模态弹窗口,关闭后显示在载体界面中
- 用github管理自己的项目
- cxf WebService整合Spring
- Bootstrap学习--下拉菜单
- FreeMarker语法知识
- web.xml中load-on-startup的作用