1.项目使用springboot 2.1.3版本,集成webservice使用的依赖如下

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.1.3.RELEASE</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>
  7. <!-- cxf webservice -->
  8. <dependency>
  9. <groupId>org.apache.cxf</groupId>
  10. <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
  11. <version>3.2.4</version>
  12. </dependency>

2.编写服务接口

  1. package com.example.demo.service;
  2.  
  3. import javax.jws.WebMethod;
  4. import javax.jws.WebService;
  5.  
  6. @WebService
  7. public interface WebServiceTest {
  8.  
  9. @WebMethod //声明暴露服务的方法,可以不写
  10. public String getMsg(String msg);
  11. }

3.编写业务方法

  1. package com.example.demo.service.impl;
  2.  
  3. import java.util.Random;
  4.  
  5. import javax.jws.WebService;
  6.  
  7. import org.slf4j.Logger;
  8. import org.slf4j.LoggerFactory;
  9. import org.springframework.stereotype.Component;
  10.  
  11. import com.example.demo.service.WebServiceTest;
  12.  
  13. @WebService(targetNamespace="http://service.demo.example.com/",
  14. endpointInterface="com.example.demo.service.WebServiceTest")
  15. @Component
  16. public class WebServiceTestImpl implements WebServiceTest {
  17.  
  18. private static final Logger log = LoggerFactory.getLogger(WebServiceTestImpl.class);
  19.  
  20. @Override
  21. public String getMsg(String msg) {
  22. log.info("客户端发来的参数:{}",msg);
  23. String serviceMsg = "hello,I'm server client."+new Random().nextLong();
  24. return serviceMsg;
  25. }
  26.  
  27. }

注意:接口和接口实现类不在同一包下

4.发布服务类

  1. package com.example.demo.config;
  2.  
  3. import javax.xml.ws.Endpoint;
  4.  
  5. import org.apache.cxf.Bus;
  6. import org.apache.cxf.jaxws.EndpointImpl;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Bean;
  9. import org.springframework.context.annotation.Configuration;
  10.  
  11. import com.example.demo.service.WebServiceTest;
  12.  
  13. @Configuration
  14. public class CxfConfig {
  15.  
  16. @Autowired
  17. private Bus bus;
  18.  
  19. @Autowired
  20. private WebServiceTest webServiceTest;
  21.  
  22. @Bean
  23. public Endpoint endpoint() {
  24. EndpointImpl endpoint = new EndpointImpl(bus, webServiceTest);
  25. endpoint.publish("/user");
  26. return endpoint;
  27. }
  28. }

5.远程访问的地址:http://ip:端口/项目路径/services/user?wsdl  来查看你的wsdl文件

6.客户端调用

在另一项目里,一样需要引入上面的依赖

  1. <!-- cxf webservice -->
  2. <dependency>
  3. <groupId>org.apache.cxf</groupId>
  4. <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
  5. <version>3.2.4</version>
  6. </dependency>

然后:

  1. package com.example.demo;
  2.  
  3. import org.apache.cxf.endpoint.Client;
  4. import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
  5. import org.junit.Test;
  6. import org.junit.runner.RunWith;
  7. import org.springframework.boot.test.context.SpringBootTest;
  8. import org.springframework.test.context.junit4.SpringRunner;
  9.  
  10. @RunWith(SpringRunner.class)
  11. @SpringBootTest
  12. public class SpringWebserviceClientApplicationTests {
  13.  
  14. @Test
  15. public void contextLoads() {
  16. }
  17. @Test
  18. public void test() {
  19. // 创建动态客户端
  20. JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
  21. Client client = dcf.createClient("http://localhost:8080/services/user?wsdl");
  22. Object[] objects = new Object[0];
  23. try {
  24.        objects = client.invoke("getMsg", "hello,我是客户端哦!");
  25. System.out.println("返回数据:" + objects[0]);
  26. } catch (java.lang.Exception e) {
  27. e.printStackTrace();
  28. }
  29. }
  30. }

提示:我是在springboot测试包里面测试的,你也可以直接写个main方法进行测试。

接下来敲黑板划重点:

1.@WebService(targetNamespace="http://service.demo.example.com/", endpointInterface="com.example.demo.service.WebServiceTest")  这个注解里面targetNamespace是一定要写的,这是指名我们暴露出去的接口在哪,不写映射不到,就会报No operation was found with the name {...}这个错误 ,endpointInterface="com.example.demo.service.WebServiceTest" 这个是告诉接口是哪个

2.请注意targetNamespace最后面有一个斜线我就是因为没加斜线,老是报上面那个错误,真的是弄了一天,有时候一个小小的符号就够你忙活一天的了。深痛的教训啊。。。。。

3.远程访问地址:http://xxxx/services/user?wsdl 后面加粗部分是固定写法,当然你要是重新配置了这个wsdl的访问路径,就需要使用你配置的,这里就不写怎么配置了,感觉没啥用。。。,有感兴趣的可以百度搜搜看

最后,有不对的欢迎指出纠正!

springboot2.1.3集成webservice及错误No operation was found with the name {...}解决办法的更多相关文章

  1. 调用 WebService 浏览器提示 500 (Internal Server Error) 的原因及解决办法

    在 ASP.NET 开发中,WebService部署成站点之后,如果在本地测试WebService可以运行,在远程却显示“测试窗体只能用于来自本地计算机的请求”或 者"The test fo ...

  2. CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法

    CAS (10) -- JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法 jboss版本: jb ...

  3. 远程连接MySQL错误“plugin caching_sha2_password could not be loaded”的解决办法

    远程连接MySQL错误"plugin caching_sha2_password could not be loaded"的解决办法 问题描述: 今天在阿里云租了一个服务器,当我用 ...

  4. 用eclipse碰到的一些错误,然后自己去网上找的解决办法

    错误一: [Please check logcat output for more details.Launch canceled! 解决办法:在配置文件:AndroidManifest.xml加入如 ...

  5. 彻底解决phpcms v9升级后,文章发布出现: Mysql 1267错误:MySQL Error : Illegal mix of collations 解决办法

    彻底解决phpcms v9升级后,文章发布出现: MySQL Query : SELECT * FROM `withli_a`.`v9_keyword` WHERE `keyword` = '吼吼' ...

  6. make -f dc_debug.mak 提示错误"/usr/bin/ld:can not find -l***"解决办法

    在公司不同服务器上"make -f ***"程序的时候,有的服务器可以编译通过,有的却提示"/usr/bin/ld:can not find -l***"的错误 ...

  7. vs错误【C1083 C1854 C4727】的若干解决办法(对预编译文件头的解释)

    这几天写程序,无意间把编译中间文件给删了,然后就出现了C1083编译错误. xxx.cpp ..\commen\xxx.cpp(2) : fatal error C1083: 无法打开预编译头文件:“ ...

  8. VC++编译错误error C2065: “HANDLE”: 未声明的标识符及添加winbase.h后提示winbase.h(243): error C2146: 语法错误: 缺少“;”(在标识符“Internal”的前面)的解决办法

    问题描述: VC++程序编译时提示错误:error C2065: “HANDLE”: 未声明的标识符等众多错误提示,如下所示: error C2065: “HANDLE”: 未声明的标识符 error ...

  9. 变色龙启动MAC时,错误信息“ntfs_fixup: magic doesn't match:”的解决办法

    如下是变色龙启动的bdmesg,解决办法就是用mac的磁盘管理器,对ntfs分区进行检验修复.需要安装ntfs的驱动支持. 实在不行,就删除调整过大小的分区,重新用Windows的磁盘管理器重新分区. ...

随机推荐

  1. Tortoise SVN 使用

    1.添加文件或文件夹 2.删除文件或文件夹 ①If you want to delete an item from the repository, but keep it locally as an ...

  2. Spark源码分析 – DAGScheduler

    DAGScheduler的架构其实非常简单, 1. eventQueue, 所有需要DAGScheduler处理的事情都需要往eventQueue中发送event 2. eventLoop Threa ...

  3. Python 面向对象进阶(二)

    1. 垃圾回收 小整数对象池 Python对小整数的定义是 [-5, 257),这些整数对象是提前建立好的; 在一个Python程序中,所有位于这个范围内的整数,使用的都是同一个对象; 单个字符共用对 ...

  4. Python用MySQLdb, pymssql 模块通过sshtunnel连接远程数据库

    转载自 https://www.cnblogs.com/luyingfeng/p/6386093.html 安全起见,数据库的访问多半是要做限制的,所以就有一个直接的问题是,往往多数时候,在别的机器上 ...

  5. CheckStyle——检查编码格式等是否符合规范

    CheckStyle 一.checkstyle简介 checkstyle是idea中的一个插件,可以很方便的帮我们检查java代码中的格式错误,它能够自动化代码规范检查过程,从而使得开发人员从这项重要 ...

  6. 工作中发现Web服务器的磁盘满后故障分析

    遇到的问题:   今天收到报警,某台线上的服务器的磁盘已满,但是登上去使用du -sh /log/* 检查, 发现文件的大小远远小于磁盘的空间,此时不知道该如何解决! 解决的方法:   其实,如果只是 ...

  7. Spring框架第五篇之Spring与AOP

    一.AOP概述 AOP(Aspect Orient Programming),面向切面编程,是面向对象编程OOP的一种补充.面向对象编程是从静态角度考虑程序的结构,而面向切面编程是从动态角度考虑程序运 ...

  8. matplotlib显示栅格图片

    参考自Matplotlib Python 画图教程 (莫烦Python)(13)_演讲•公开课_科技_bilibili_哔哩哔哩 https://www.bilibili.com/video/av16 ...

  9. Android Study Notes

    @1:按下back键退回到home界面时,会调用onDestroy() 按下back键时会调用onDestroy()销毁当前的activity,重新启动此activity时会调用onCreate()重 ...

  10. Xcode插件开发案例教程

    引言 在平时开发过程中我们使用了很多的Xcode插件,虽然官方对于插件制作没有提供任何支持,但是加载三方的插件,默认还是被允许的.第三方的插件,存放在 ~/Library/Application Su ...