springboot+cxf 发布服务接口简单例子

1、创建服务类,用于发布webservice接口 

import javax.xml.ws.Endpoint;



import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CXFServer {

    @Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
    }
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    @Bean
    public UserService userService() {//UserService  为业务接口类
        return new UserManager();
    }
    @Bean
    public Endpoint endpoint() { 
        EndpointImpl endpoint = new EndpointImpl(springBus(),this.userService());
        endpoint.publish("/user");
        return endpoint;
    }

}



2、成功后可在http://localhost:8800/soap/user 看到

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode> soap:Server </faultcode>
<faultstring>
No binding operation info while invoking unknown method with params unknown.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>


注:需先在在pom.xml中加入mvn依赖包:

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



具体详情可见:http://blog.csdn.net/hj7jay/article/details/51130386

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值