使用CXF和spring搭建webService服务
2023-09-14 09:04:42 时间
虽然下一个项目需要使用xfire,但是在查资料的过程中还是看到有不少地方都说cxf比xfire更好,cxf继承了xfire,但是不仅仅包含xfire,因此便也一起来尝试尝试。大概是有了xfire的经验吧,cxf的搭建比xfire快了许多。
cxf的许多参数感觉和xfire差不多,因此便不做太多的解释,如果不明白的可以参考之前的xfire搭建来促进理解。
搭建过程如下:
1、使用eclipse创
7、页面正常访问后,我新建一个一个项目,导入了服务端导入的所有的jar包,然后写了个简单的main方法进行测试。需要注意的是,跟xfire一样,这里也需要写一个和服务端一模一样的服务接口(包路径可以不一样),如: package cxfTest1; import javax.jws.WebService; @WebService(serviceName = "CxfTestService", targetNamespace = "http://cxfTest") public interface CxfTestService { public String getUserName(); 然后对应的模拟客户端调用代码如下: package cxfTest1; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; public class CxfTest { public static void main(String[] args) { JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean(); // factoryBean.getInInterceptors().add(new LoggingInInterceptor()); // factoryBean.getOutInterceptors().add(new LoggingOutInterceptor()); factoryBean.setServiceClass(CxfTestService.class); factoryBean .setAddress("http://localhost:8082/cxfTest/services/CxfTestService"); CxfTestService impl = (CxfTestService) factoryBean.create(); System.out.println(impl.getUserName()); } 上边被注释的代码也是日志相关的,加不加都不影响主要业务功能,可以自己选择用还是不用。执行main方法后控制台输出如下:![](http://img.blog.csdn.net/20160608173221022?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
使用CXF和spring搭建webService服务 虽然下一个项目需要使用xfire,但是在查资料的过程中还是看到有不少地方都说cxf比xfire更好,cxf继承了xfire,但是不仅仅包含xfire,因此便也一起来尝试尝试。大概是有了xfire的经验吧,cxf的搭建比xfire快了许多。 cxf的许多参数感觉和xfire差不多,因此便不做太多的解释,如果不明白的可以参考之前的xfire搭建来促进理解。 搭建过程如下: 1、使用eclipse创
涂宗勋 认真生活,快乐工作,保持理想!https://blog.csdn.net/tuzongxun
7、页面正常访问后,我新建一个一个项目,导入了服务端导入的所有的jar包,然后写了个简单的main方法进行测试。需要注意的是,跟xfire一样,这里也需要写一个和服务端一模一样的服务接口(包路径可以不一样),如: package cxfTest1; import javax.jws.WebService; @WebService(serviceName = "CxfTestService", targetNamespace = "http://cxfTest") public interface CxfTestService { public String getUserName(); 然后对应的模拟客户端调用代码如下: package cxfTest1; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; public class CxfTest { public static void main(String[] args) { JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean(); // factoryBean.getInInterceptors().add(new LoggingInInterceptor()); // factoryBean.getOutInterceptors().add(new LoggingOutInterceptor()); factoryBean.setServiceClass(CxfTestService.class); factoryBean .setAddress("http://localhost:8082/cxfTest/services/CxfTestService"); CxfTestService impl = (CxfTestService) factoryBean.create(); System.out.println(impl.getUserName()); } 上边被注释的代码也是日志相关的,加不加都不影响主要业务功能,可以自己选择用还是不用。执行main方法后控制台输出如下:
使用CXF和spring搭建webService服务 虽然下一个项目需要使用xfire,但是在查资料的过程中还是看到有不少地方都说cxf比xfire更好,cxf继承了xfire,但是不仅仅包含xfire,因此便也一起来尝试尝试。大概是有了xfire的经验吧,cxf的搭建比xfire快了许多。 cxf的许多参数感觉和xfire差不多,因此便不做太多的解释,如果不明白的可以参考之前的xfire搭建来促进理解。 搭建过程如下: 1、使用eclipse创
涂宗勋 认真生活,快乐工作,保持理想!https://blog.csdn.net/tuzongxun
相关文章
- 防止内卷和被潜规则,Spring Cloud Alibaba微服务架构实战派(上下册)|35岁程序员那些事
- Spring Cloud 微服务优雅下线 + 灰度发布的正确姿势,写得太好了!
- 简单介绍一下spring bean的生命周期_Spring bean的生命周期
- Spring到底学到什么程度才算学会?
- 基于spring-security的微服务鉴权中心
- spring-boot-devtools在Idea中热部署
- 微服务组件--注册中心Spring Cloud Eureka分析
- 搭建spring cloud框架并且配置权限架构
- Spring基础(二):IOC概念引入
- spring boot微服务通用部署启动脚本
- Spring Cloud 微服务实战——nacos 服务注册中心搭建(附源码)
- Spring Boot的数据绑定和参数传递(一)
- Spring Cloud LoadBalancer 的高级特性-服务实例过滤器(一)
- Spring Cloud LoadBalancer 的高级特性-服务实例过滤器(二)
- 使用 Spring Cloud Bus 向指定的微服务发送消息
- Spring Cloud 入门教程(十):和RabbitMQ的整合 — 消息总线Spring Cloud Netflix Bus详解编程语言
- Spring Cloud之Swagger集群搭建详解编程语言
- Spring Boot(四):thymeleaf使用详解编程语言
- Spring DI(依赖注入)的实现方式:属性注入和构造注入
- Spring通知类型及使用ProxyFactoryBean创建AOP代理
- Spring框架致力于搭建基于MSSQL的稳健开发体系(spring mssql)