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

 <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- cxf webservice -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.4</version>
</dependency>

2.编写服务接口

 package com.example.demo.service;

 import javax.jws.WebMethod;
import javax.jws.WebService; @WebService
public interface WebServiceTest { @WebMethod //声明暴露服务的方法,可以不写
public String getMsg(String msg);
}

3.编写业务方法

package com.example.demo.service.impl;

import java.util.Random;

import javax.jws.WebService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import com.example.demo.service.WebServiceTest; @WebService(targetNamespace="http://service.demo.example.com/",
endpointInterface="com.example.demo.service.WebServiceTest")
@Component
public class WebServiceTestImpl implements WebServiceTest { private static final Logger log = LoggerFactory.getLogger(WebServiceTestImpl.class); @Override
public String getMsg(String msg) {
log.info("客户端发来的参数:{}",msg);
String serviceMsg = "hello,I'm server client."+new Random().nextLong();
return serviceMsg;
} }

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

4.发布服务类

 package com.example.demo.config;

 import javax.xml.ws.Endpoint;

 import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import com.example.demo.service.WebServiceTest; @Configuration
public class CxfConfig { @Autowired
private Bus bus; @Autowired
private WebServiceTest webServiceTest; @Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, webServiceTest);
endpoint.publish("/user");
return endpoint;
}
}

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

6.客户端调用

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

 <!-- cxf webservice  -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.2.4</version>
</dependency>

然后:

package com.example.demo;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@SpringBootTest
public class SpringWebserviceClientApplicationTests { @Test
public void contextLoads() {
}
@Test
public void test() {
// 创建动态客户端
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8080/services/user?wsdl");
Object[] objects = new Object[0];
try {
       objects = client.invoke("getMsg", "hello,我是客户端哦!");
System.out.println("返回数据:" + objects[0]);
} catch (java.lang.Exception e) {
e.printStackTrace();
}
}
}

提示:我是在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. 【Python Programe】WSGI (Web Server Gateway Interface)

    Part1: What is a Web server? 一个位于物理服务器上的网络服务器(服务器里的服务器),等待客户端去发送request,当服务器接收到request,就会生成一个respons ...

  2. order meeting room - 离散度30min

    w <meta charset="UTF-8"> <?php include('conn.php'); include('w_fun.php'); include ...

  3. golang处理 json中非法字符

    原文: Hi there, I just discovered Go and decided to port a little program to Go. The program reads JSO ...

  4. Linux命令(1)——xargs命令

    1.功能: xargs能够将stdin中以空格或换行符进行分隔的数据.形成以空格分隔的參数(arguments),传递给其它命令.由于以空格作为分隔符,所以有一些文件名称或者其它意义的名词内含有空格的 ...

  5. Python3 格式化输出 %s & %d 等

    1.打印字符串 print("My name is %s" %("Alfred.Xue")) #输出效果:My name is Alfred.Xue 2.打印整 ...

  6. SpringBoot安装和创建简单的Web应用

    SpringBoot安装 方式一: Eclipese->Help->Eclipse Marketplace ->Finde STS -> Install 注意:安装过程中挺慢, ...

  7. 一个父亲的教育札记——leo鉴书58

    由于年纪和工作的原因.绝大部分小说我都不看--没空,如今小说写的也太空.但对文笔有提高的文章我是非常关注的,知道韩寒不是由于<三重门>(我报纸也不怎么看).而是此前编辑感觉我文笔差.   ...

  8. Spark2.0机器学习系列之9: 聚类(k-means,Bisecting k-means,Streaming k-means)

    在Spark2.0版本中(不是基于RDD API的MLlib),共有四种聚类方法:      (1)K-means      (2)Latent Dirichlet allocation (LDA)  ...

  9. 玩转DOM遍历——用NodeIterator实现getElementById,getElementsByTagName方法

    先声明一下DOM2中NodeIterator和TreeWalker这两类型真的只是用来玩玩的,因为性能不行遍历起来超级慢,在JS中基本用不到它们,除了<高程>上有两三页对它的讲解外,谷歌的 ...

  10. Python数据库连接池实例——PooledDB

    不用连接池的MySQL连接方法 import MySQLdb conn= MySQLdb.connect(host='localhost',user='root',passwd='pwd',db='m ...