小编典典

带Spring Boot的CXF

spring-boot

我试图让CXF和Sprint Boot正常播放。我有一个名为SubscriberApi的JAX-WS服务端点。查看spring-
boot日志,我看到成功的映射:

Mapping servlet: 'CXFServlet' to [/api/*]
Setting the server's publish address to be /SubscriberApi

但是,我似乎无法在点击时获得WSDL:

http://localhost:8080/api/SubscriberApi?wsdl



@Configuration
@ImportResource({"classpath:META-INF/cxf/cxf.xml"})
public class CxfConfiguration  {
  @Bean
  public SubscriberApi subscriberApi() {
    return new SubscriberApi();
  }
  @Bean
  public ServletRegistrationBean servletRegistrationBean() {
    CXFServlet cxfServlet = new CXFServlet();

    ServletRegistrationBean servletRegistrationBean =
        new ServletRegistrationBean(cxfServlet, "/api/*");
    servletRegistrationBean.setLoadOnStartup(1);
    return servletRegistrationBean;
  }
  @DependsOn("servletRegistrationBean")
  @Bean
  public Endpoint jaxwsEndpoint(SubscriberApi subscriberApi){
    javax.xml.ws.Endpoint jaxwsEndpoint =
        javax.xml.ws.Endpoint.publish("/SubscriberApi", subscriberApi);
      return jaxwsEndpoint;
  }
 }

阅读 307

收藏
2020-05-30

共1个答案

小编典典

让您的jaxwsEndpointbean返回的实例org.apache.cxf.jaxws.EndpointImpl,该实例扩展为javax.xml.ws.Endpoint

@Autowired
private ApplicationContext applicationContext;

@DependsOn("servletRegistrationBean")
@Bean
public Endpoint jaxwsEndpoint(){
   Bus bus = (Bus) applicationContext.getBean(Bus.DEFAULT_BUS_ID);
   EndpointImpl endpoint = new EndpointImpl(bus, subscriberApi());
   endpoint.publish("/SubscriberApi");
   // also showing how to add interceptors
   endpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor());
   endpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor());

   return endpoint;
}

原始帖子不包含可运行的示例,但这应该可以解决问题。

可以在此处找到一个正在运行的示例,并将所有配置链接在一起:
Application.java

2020-05-30