我正在尝试使用基于Java的配置(没有Spring Boot)来设置CXF Web服务,但会收到异常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>