Springboot集成webservice接口

接口类

  1. 添加@WebService注解,name作为唯一标识
  2. 添加@SOAPBinding注解,指定rpc方式调用
  3. 需开放的方法添加@WebMethod注解
  4. 方法需要传参的话,参数添加@WebParam注解
@WebService(name = "commandService")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface CommandService {

    @WebMethod
    public String command(@WebParam(name = "userid") String userid);
}

接口实现类

  1. 添加@Service注解,接口注册
  2. 添加@WebService注解,与接口@WebService注解 name名保持一致
@Service
@WebService(serviceName = "commandService")
@Slf4j
public class CommandServiceImpl implements CommandService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public String command(String enterpriseId, String randVal, String pwdHash,
                          String command, String commandSign, int commandType,
                          int encryptAlgorithm, int hashAlgorithm, String commandVersion) {
        //接口实现逻辑
        
    }
    
}

接口发布

  1. 配置类中添加@Configuration进行注册
  2. cxfServletRegistration(),声明webservice接口对外一级路径
  3. endpointCmdService(),声明指定接口对外二级路径(方法名可自定义,一级路径+二级路径即为接口完整访问路径)
  4. 多个接口发布声明多个接口和接口对应二级路径即可
@Configuration
public class WebServiceConfig {

    @Autowired
    private CommandService commandService;

    @Autowired
    private CommandAckService commandAckService;

    @Bean
    public ServletRegistrationBean<CXFServlet> cxfServletRegistration() {
        ServletRegistrationBean<CXFServlet> registration = new ServletRegistrationBean(new CXFServlet(), "/lxl-manager-web/ws/*");
        return registration;
    }

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


    @Bean
    public Endpoint endpointCmdService() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), commandService);
        endpoint.publish("/command");
        return endpoint;
    }

    @Bean
    public Endpoint endpointCmdAckService() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), commandAckService);
        endpoint.publish("/commandAck");
        return endpoint;
    }

}

接口访问路径

http: ip:port/lxl-manager-web/ws/command?wsdl

http: ip:port/lxl-manager-web/ws/commandAck?wsdl

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值