SpringBoot集成CXF发布WebService服务

29 篇文章 11 订阅

环境说明

SpringBoot版本:2.5.6

JDK版本:Jdk8_update261

ApacheCXF版本:3.4.4

依赖引入

在pom文件中引入如下依赖。

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

接口服务

package com.purvar.webservice;

import com.alibaba.fastjson.JSON;
import com.purvar.controller.agile.ManufactureController;
import com.purvar.domain.ManufactureVO;
import com.purvar.service.IManufactureService;
import com.purvar.vo.Result;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.util.JSONUtil;
import io.swagger.util.Json;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jws.WebService;

/**
 * PLM公共WebService服务<br>
 * @author namelessmyth
 * @version 1.0
 * @date 2022/12/9/0009
 */
@WebService(serviceName = "PlmWebService", targetNamespace = "http://www.purvar.com")
public class PlmWebService {
    @Autowired
    private IManufactureService manufactureService;

    public String saveManu(@WebParam(name = "input") String input) throws Exception {
        Result result = null;
        try {
            ManufactureVO vo = JSON.parseObject(input, ManufactureVO.class);
            result = manufactureService.save(vo);
        } catch (Exception e) {
            result = new Result(e);
        }
        return JSON.toJSONString(result);
    }
}

服务配置

package com.purvar.webservice;

import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.Bus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * CXF-Webservice配置类<br>
 *
 * @author namelessmyth
 * @version 1.0
 * @date 2022/12/9/0009
 */
@Configuration
public class CxfConfig {
    @Autowired
    private Bus bus;

    @Bean
    public Endpoint endpointPlmWebService() {
        EndpointImpl endpoint = new EndpointImpl(bus, new PlmWebService());
        //WebService服务路径
        endpoint.publish("/PlmWebService");
        return endpoint;
    }
}

如果项目使用了Shiro还需要在shiro中将servies加入地址过滤,否则会被登录拦截器拦截。

filterChainDefinitionMap.put("/services/**", "anon");

然后启动SpringBoot项目。在浏览器中输入WebService的地址:http://localhost:8081/services/PlmWebService?wsdl会出现如下界面

客户端调用

使用SoapUI工具调用WebService服务

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值