springboot+cxf 搭建webservice接口项目

发布时间:2020-03-19   来源:文档文库   
字号:
一、 项目开发环境
1.jdk 1.8 2.springboot 2.0.3 3.cxf 3.2.6 注意:springboot 版本过高可能会和cxf冲突 导致项目启动报错
二、 搭建
1. 创建项目后添加以下依赖
org.springframework.boot spring-boot-starter-parent 2.0.3.RELEASE 3.1.1 1.8
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test org.apache.cxf cxf-spring-boot-starter-jaxws 3.2.6



org.springframework.boot spring-boot-maven-plugin org.apache.maven.plugins maven-compiler-plugin 1.8 1.8 UTF-8 2. 创建一个接口类
@WebService(targetNamespace = "http://xxx.xxx.xxx/"// 命名空间,一般是接口的包名倒序
public interface TestService {
@WebMethod public String test(@WebParam(name = "userName" String name; }
之后创建接口的实现类
public class TestServiceImpl implements TestService {

@Override public String test(String name { // TODO Auto-generated method stub return "hellow"; }
} 3. 创建cxfconfig配置类
package com.gsww.chis.config;

import javax.xml.ws.Endpoint;
import org.apache.cxf.jaxws.EndpointImpl; import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.transport.servlet.CXFServlet; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;
import com.gsww.chis.webservice.TestService; import com.gsww.chis.webservice.impl.TestServiceImpl;
@Configuration public class CxfConfig {
@Bean(name = Bus.DEFAULT_BUS_ID public SpringBus springBus( { return new SpringBus(; }

/** * 此方法被注释后:wsdl访问地址为http://127.0.0.1:8080/services/user?wsdl * 去掉注释后:wsdl访问地址为:http://127.0.0.1:8080/soap/user?wsdl
*/ @SuppressWarnings({ "rawtypes", "unchecked" }
@Bean public ServletRegistrationBean dispatcherServlet( { return new ServletRegistrationBean(new CXFServlet(, "/soap/*"; }

@Bean public TestService testService( { return new TestServiceImpl(; }

/** * 发布服务 指定访问url *
* @return */
@Bean public Endpoint userEndpoint( {
EndpointImpl endpoint = new EndpointImpl(springBus(, testService(;
endpoint.publish("/call"; System.out.println("发布成功"; return endpoint; }
} 3.访问路径

ip:端口/(项目配置的context-path/soap/call?wsdl

本文来源:https://www.2haoxitong.net/k/doc/5ca26ddfa66e58fafab069dc5022aaea988f414d.html

《springboot+cxf 搭建webservice接口项目.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式