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

来源:互联网 发布:java生成log日志文件 编辑:程序博客网 时间:2024/04/30 19:54

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
原创粉丝点击