简体   繁体   中英

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

I am trying to setup a CXF webservice with java based config (no Spring Boot) but get the exception 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;
    }

}

I'm confused.. what could be wrong? I searched for similar examples, but only found XML or SpringBoot examples.

I have my configuration split up into seperate files (AbstractAnnotationConfigDispatcherServletInitializer for servlet / filter config)

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/*");
    }

Turns out I was missing a dependency

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM