[英]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.