Springboot实现webservice

本文介绍了如何在Springboot应用中利用CXF框架发布Webservice接口。首先,确保本地JDK为1.8,然后添加CXF依赖。接着,定义了要发布的接口及其实现类,并创建了相应的配置类。完成配置后,通过访问http://127.0.0.1:8080/pattern/qis?wsdl可以查看发布的Webservice接口。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本地JDK:1.8
准备工作:添加CXF的依赖

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>3.2.4</version>
</dependency>
<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>2.0.1.Final</version>
</dependency>

一.定义要发布的接口和实现类

接口:

@WebService(targetNamespace = "http://webService.entryinterface.ruijie.com")
public interface QisService {

    @WebMethod
    String pattern(@WebParam(name = "xml") String xml) throws Exception;

}

实现类:

// serviceName=对外发布的服务名,targetNamespace=指定你想要的名称空间,通常使用使用包名反转,endpointInterface=服务接口全路径
@WebService(serviceName = "QisService", targetNamespace = "http://webService.entryinterface.ruijie.com", endpointInterface = "com.ruijie.entryinterface.webService.QisService")
@Component
public class QisServiceImpl implements QisService {

    @Override
    public String pattern(String xml) throws Exception {
        ...
        return null;
    }
}

定义配置类:

@Configuration
public class CxfConfig {

    @Autowired
    private Bus bus;

    @Autowired
    QisService qisService;

    /**
     * 默认servlet路径/*,如果覆写则按照自己定义的来
     *
     * @return
     */
    @SuppressWarnings("all")
    @Bean
    public ServletRegistrationBean cxfServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/pattern/*");
    }

    @Bean
    ServletWebServerFactory servletWebServerFactory() {
        return new TomcatServletWebServerFactory();
    }

    /**
     * JAX-WS 站点服务
     **/
    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, qisService);
        endpoint.publish("/qis");
        return endpoint;
    }
}

启动完成后,输入地址:http://127.0.0.1:8080/pattern/qis?wsdl在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值