簡體   English   中英

發布 Apache CXF 服務時出現異常(java 配置,無 Spring Boot)

[英]Exception while publishing Apache CXF service (java config, no Spring Boot)

我正在嘗試使用基於 Java 的配置(無 Spring Boot)設置 CXF 網絡服務,但得到異常 org.apache.cxf.service.factory.ServiceConstructionException

package com.sandbox.configuration;

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.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.sandbox.cxf.SandboxWSImpl;

@Configuration
public class SandboxCXFConfiguration {

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), new SandboxWSImpl());
        endpoint.publish("http://localhost:8080/sandboxWS"); // crashes here
        return endpoint;
    }

}

我很困惑.. 可能有什么問題? 我搜索了類似的示例,但只找到了 XML 或 SpringBoot 示例。

我將我的配置拆分為單獨的文件(用於 servlet/過濾器配置的 AbstractAnnotationConfigDispatcherServletInitializer)

AbstractAnnotationConfigDispatcherServletInitializer

@Override
    protected Class<?>[] getServletConfigClasses() {
       return new Class[] { SandboxConfiguration.class, SandboxCXFConfiguration.class };
    }
@Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        registerJAXWSServlet(servletContext);
    }

    private void registerJAXWSServlet(ServletContext servletContext) {
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("cxf-service", new CXFServlet());
        dispatcher.addMapping("/services/*");
    }

原來我錯過了一個依賴

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>${cxf.version}</version>
</dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM