作者:@展云
本文为作者原创,转载请注明出处:https://www.cnblogs.com/zhanxiaoyun/p/7942902.html


目录

一、CXF与Spring整合(jaxws:endpoint形式配置)
1.新建一个maven项目
2.web.xml文件中配置CXFServlet以及Spring容器,配置Spring的配置文件,配置webservice的配置文件
二、客户端调用(spring配置文件形式,不需要生成客户端代码)
1.spring配置文件信息
2.写对应接口信息
3.加载Spring的配置文件进行测试
4.需要的jar包

一、CXF与Spring整合(jaxws:endpoint形式配置)

工具要点:idea、maven

1.新建一个maven项目

 pom.xml

2.web.xml文件中配置CXFServlet以及Spring容器,配置Spring的配置文件,配置webservice的配置文件

web.xml:

 web.xml

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:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"><!-- 使用annotation 自动注册bean,并检查@Required,@Autowired的属性已被注入 --><context:component-scan base-package="com.wp.learn.webservice"></context:component-scan><!-- 导入其他配置文件 --><import resource="applicationContext-ws.xml" /></beans>

applicationContext-ws.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:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.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="helloWebservice" implementor="#helloServiceImpl"address="/hello" />
</beans>

接口HelloService:

Impl类HelloServiceImpl:

情况一、如果Impl类的注解是@Webservice,implementor需要写完全路径

情况二、Impl类注解是@Service,implementor只需“#”号加bean的id名

二、客户端调用(spring配置文件形式,不需要生成客户端代码)

  Webservice的客户端调用,可以用ajax前端调用,java中可以通过生产客户端代码调用,也可以通过Spring配置文件、写对应接口信息调用。本例介绍配置文件,写接口信息进行webservice调用。

1.spring配置文件信息

<jaxws:client id="helloService" serviceClass="com.wp.learn.webservice.cxf.service.IHelloService"address="http://localhost:8080/ws/HelloService">
</jaxws:client>

2.写对应接口信息

需要注意两点:

  • 1、targetNamespace的值必须和webservice服务项目中定义的一致,具体信息可以在WSDL文件中查看
  • 2、接口名称可以自己随便起,但是方法名称、参数格式必须保持一致,否则无法找到服务的实现方法。

//注意,该出的targetNamespace的值必须和webService服务项目中定义的必须一致,否则调用不成功
@WebService(targetNamespace = "http://impl.service.cxf.webservice.learn.wp.com/", name = "IHelloService")
public interface IHelloService {//接口名称可以不一样,方法名称、参数格式必须保持一致,否则无法找到服务的实现的方法public String sayHi(String name);
}

3.加载Spring的配置文件进行测试

public class Test {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-ws.xml");IHelloService helloService = (IHelloService) context.getBean("helloService");String result = helloService.sayHi("帅哥");System.out.print(result);}
}

4.需要的jar包

 pom.xml

源码地址:https://gitee.com/wangpinggs/learn/tree/master/webserviceDemo

WebService--CXF与Spring的整合(jaxws:endpoint形式配置)以及客户端调用(spring配置文件形式,不需要生成客户端代码)相关推荐

  1. MongoDB和Java(4):Spring Data整合MongoDB(XML配置)

    最近花了一些时间学习了下MongoDB数据库,感觉还是比较全面系统的,涉及了软件安装.客户端操作.安全认证.副本集和分布式集群搭建,以及使用Spring Data连接MongoDB进行数据操作,收获很 ...

  2. MongoDB和Java(5):Spring Data整合MongoDB(注解配置)

    最近花了一些时间学习了下MongoDB数据库,感觉还是比较全面系统的,涉及了软件安装.客户端操作.安全认证.副本集和分布式集群搭建,以及使用Spring Data连接MongoDB进行数据操作,收获很 ...

  3. Spring Cloud整合Nacos实现动态配置

    前提 已经安装并启动了nacos-server服务端. 整合 创建一个maven工程并引入以下依赖: <dependency><groupId>org.springframew ...

  4. Spring Boot 整合携程Apollo 配置中心

    作者:AaronSimon blog.csdn.net/AaronSimon/article/details/83657612 Apollo(阿波罗)是携程框架部门研发的分布式配置中心,能够集中化管理 ...

  5. Spring Boot概述与入门特点配置方式注入方式yim配置文件与多文件配置Spring Boot自动配置原理lombok应用

    1. Spring Boot概述 Spring Boot是Spring项目中的一个子工程,与我们所熟知的Spring-framework 同属于spring的产品: 首页Spring Boot简介可以 ...

  6. Spring入门详解(一)如何配置一个简单的spring项目

    关于spring的一些概念,网上已经有很多的说明,本系列不会做太多的描述,重心在如何配置上. 一.准备工作 1.安装JDK,配置环境.(本来不想写这条的-想了想,还是写上) 2.下载开发包 Sprin ...

  7. Spring boot整合nacos注册中心/配置中心报错:java.lang.IllegalArgumentException: no server available

    1.问题描述 我是近期在使用Springboot整合nacos,由于springboot和springcloud都是用最新版本,啪的一下,很快啊,就出现问题了,于是自己把版本降下来了,年轻人不讲武德降 ...

  8. 基于注解的Spring MVC整合Hibernate(所需jar包,spring和Hibernate整合配置,springMVC配置,重定向,批量删除)

    1.导入jar 2.web.xml配置 <?xml version="1.0" encoding="UTF-8"?> <web-app ver ...

  9. spring cloud整合OpenFeign

    spring cloud整合OpenFeign pom.xml配置 <!-- https://mvnrepository.com/artifact/org.springframework.clo ...

  10. Spring Boot(十四):spring boot整合shiro-登录认证和权限管理

    Spring Boot(十四):spring boot整合shiro-登录认证和权限管理 使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉 ...

最新文章

  1. java面试常见问题之Hibernate总结
  2. # Ubuntu 配置自带vnc桌面共享
  3. 网页标准HTML5标准较量正酣
  4. Packet for query is too large (1166 1024). You can change this value
  5. Android在UI线程访问数据库,Android UI Operation in Thread
  6. Flink SQL的N way join
  7. 学习 wxpython_序
  8. 机器学习算法GBDT的面试总结
  9. mac/centos下添加永久alias
  10. 【微软的VDI】Windows Server 2012 RDS存储相关
  11. 绕过限制,申请Google+
  12. java线程知识点拾遗(CAS)
  13. 怎么把HTML转换成swf用迅雷,什么工具能把MP4格式转换成SWF并不降低画质
  14. Linux知识点小结--精华总结
  15. 致敬!烈日下的测绘者,请为他们点赞!
  16. SpringBoot系列之Spring Data MongoDB教程
  17. App Store上下载和安装Xcode
  18. 知乎:在卡内基梅隆大学 (Carnegie Mellon University) 就读是怎样一番体验?
  19. Crawlab(crawlab github)
  20. 房屋管理小程序的功能

热门文章

  1. shopee虾皮面试题汇总-C++后端
  2. 【译】网页像素追踪原理
  3. Qt 小例子学习14 - 动态滚动QScrollArea
  4. mac 上安装selenium, phantomjs 和 chromedriver
  5. ROMS四维变分测试
  6. 2021-2027全球与中国气溶胶检测器市场现状及未来发展趋势
  7. Springcloud微服务中多模块重复代码重构成公共模块的实现
  8. 模拟电路64(滤波电路)
  9. 预测股票涨跌看什么指标,如何预测明天股票走势
  10. 倒车影像辅助线怎么看_倒车影像怎么看图解