Springboot整合CXF发布WebService

简介: Springboot整合CXF发布WebService

前言

最近项目里用到WebService,之前用过,后来好久没有接触过,都忘得差不多了,再加上,以前没有写东西的癖好,所以当听到用WebService事,当场懵逼,然后赶紧找资料补救下,但是网上的资料怎么讲呢?完全不能用。。。后来在网上东凑西凑,然后请教了一下别人才搞出来的。废话不多说,我们来一起看看,怎么成功的部署一个WebService服务吧。

引入maven依赖

<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-spring-boot-starter-jaxws -->
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>3.2.6</version>
</dependency>

测试实体代码

@Data
@NoArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class User implements Serializable {

    Long id;

    String name;

    String phone;

}

接口代码

@WebService(targetNamespace = "cxf")
public interface CxfService {

    /**
     * 获取用户信息
     * @param id
     * @return
     */
    @WebMethod
    User getUser(@WebParam(name = "id") String id);
}

接口实现代码

@Service
@WebService(targetNamespace = "cxf")
public class CxfServiceImpl implements CxfService {

    @Override
    public User getUser(String id) {
        User user = new User();
        if ("1".equals(id)) {
            user.setId(1L);
            user.setName("yaoZhu");
            user.setPhone("18110981995");
            return user;
        }
        user.setId(2L);
        user.setName("luWang");
        user.setPhone("18110981995");
        return user;
    }
}

WebService发布配置代码

@Configuration
public class CxfConfig {

    @Autowired
    private CxfService cxfService;

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus(){
        return new SpringBus();
    }

    /**
     * AX-WS站点服务
     * @return
     */
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), cxfService);
        endpoint.publish("/visual");
        return endpoint;
    }
}

application.yml配置文件

cxf:
  path: /services

差不多代码写完了,那就开始测试吧!
访问路径:http://localhost:8080/services

640.png

访问路径:http://localhost:8080/services/visual?wsdl

640-1.png
这就结束了,整个项目算是大致完成了。
项目代码:https://github.com/zywaiting/springboot-cxf

相关文章
|
2月前
|
Java 数据处理
【十二】springboot整合WebService
【十二】springboot整合WebService
52 0
|
10月前
phpstorm插件应用:Test RESTful WEB Service 控制台接口调试工具
phpstorm插件应用:Test RESTful WEB Service 控制台接口调试工具
119 0
|
2月前
|
Java
【十三】springboot整合WebService关于传参数
【十三】springboot整合WebService关于传参数
20 0
|
2月前
|
存储 缓存 算法
关于 Service Worker 和 Web 应用对应关系的讨论
关于 Service Worker 和 Web 应用对应关系的讨论
14 0
|
3月前
|
Java API Apache
Apache CXF生成WebService的客户端
Apache CXF生成WebService的客户端
|
7月前
|
JSON 安全 API
使用 ABAP sproxy 事务码生成的 Proxy 消费 Web Service
使用 ABAP sproxy 事务码生成的 Proxy 消费 Web Service
57 0
|
3月前
|
XML 网络架构 数据格式
Ruby 教程 之 Ruby Web Service 应用 - SOAP4R 2
Ruby Web Service 应用 - SOAP4R
24 5
|
3月前
|
XML Linux 网络架构
Ruby 教程 之 Ruby Web Service 应用 - SOAP4R 1
Ruby Web Service 应用 - SOAP4R
23 3
|
9月前
|
XML Java API
Java Web Service Get请求使用指南
Java Web Service Get请求使用指南 在当今互联网时代,Web Service已经成为了现代软件开发中不可或缺的一部分。而Java作为一种广泛使用的编程语言,自然也提供了丰富的工具和库来支持Web Service的开发。本文将为大家介绍如何使用Java编程语言进行Web Service的Get请求。
89 0
|
5月前
|
Java 数据库连接 Apache
SpringBoot整合CXF实现WebService
SpringBoot整合CXF实现WebService
127 0