使用CXF创建Webservice服务端

1,添加依赖


    org.apache.cxf
    cxf-spring-boot-starter-jaxws
    3.2.7

2,定义webservice的接口

package com.ultrapower.ioss.projectsign.service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface ProjectSignService {
    @WebMethod
    String sendResInfo(@WebParam(name = "serSupplier") String serSupplier,
            @WebParam(name = "serCaller") String serCaller,
            @WebParam(name = "callerPwd") String callerPwd,
            @WebParam(name = "callTime") String callTime,
            @WebParam(name = "opDetail") String opDetail);
}

3,完成接口的实现

package com.ultrapower.ioss.projectsign.service.defaults;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;

import com.ultrapower.ioss.projectsign.service.ProjectSignService;

/**
 * 备注说明:接口实现类名称前的注解targetNamespace是当前类实现接口所在包名称的反序(PS:加上反斜线),
 * endpointInterface是当前需要实现接口的全称;@WebService(targetNamespace="http://service.webservicedemo.dbgo.com/",
 * endpointInterface = "com.dbgo.webservicedemo.service.UserService")
 * */
@WebService(targetNamespace="http://service.projectsign.ioss.ultrapower.com/",
endpointInterface = "com.ultrapower.ioss.projectsign.service.ProjectSignService")
public class ProjectSignWebService implements ProjectSignService {

    @Override
    public String sendResInfo(String serSupplier, String serCaller, String callerPwd, String callTime,
            String opDetail) {

        return "success";
    }

}

4,添加配置

/**
 * http://localhost:8080/services/project?wsdl
 */
@Configuration
public class WebServiceConfig {

    @Autowired
    private Bus bus;

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, projectSignService());
        endpoint.publish("/project");
        // endpoint.getInInterceptors().add(new LoggingInInterceptor());
        // endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
        Swagger2Feature feature = new Swagger2Feature();
        feature.setBasePath("/ws");
        feature.setSupportSwaggerUi(true);
        endpoint.setFeatures(Arrays.asList(new Feature[] { feature }));
        return endpoint;
    }

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

    @Bean
    public ProjectSignService projectSignService() {
        return new ProjectSignWebService();
    }
}

分享标题:使用CXF创建Webservice服务端
网页路径:http://bzwzjz.com/article/pihdpj.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 网站建设 高端网站设计 移动网站建设 定制网站制作 成都企业网站建设公司 成都网站制作 网站设计 成都网站建设 LED网站设计方案 成都网站建设公司 成都营销网站制作 成都网站建设 商城网站建设 成都网站建设 重庆网站建设 成都网站建设 成都网站建设 重庆网站建设 企业网站建设 阿坝网站设计 成都网站建设 成都网站设计制作公司