使用CXF创建Webservice服务端

发布时间:2020-06-02 17:18:31 作者:mybabe0312
来源:网络 阅读:1264

1,添加依赖

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

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();
    }
}
推荐阅读:
  1. .NET中如何创建WebService服务
  2. SpringBoot使用CXF集成WebService的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

cxf cxf创建webservice webservice

上一篇:PHP 单例模式

下一篇:mysql服务应该如何安装与配置

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》