溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

使用CXF創(chuàng)建Webservice服務(wù)端

發(fā)布時(shí)間:2020-06-02 17:18:31 來源:網(wǎng)絡(luò) 閱讀:1263 作者:mybabe0312 欄目:軟件技術(shù)

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,完成接口的實(shí)現(xiàn)

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;

/**
 * 備注說明:接口實(shí)現(xiàn)類名稱前的注解targetNamespace是當(dāng)前類實(shí)現(xiàn)接口所在包名稱的反序(PS:加上反斜線),
 * endpointInterface是當(dāng)前需要實(shí)現(xiàn)接口的全稱;@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();
    }
}
向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI