gpt4 book ai didi

java - 发布 Apache CXF 服务时出现异常(java 配置,无 Spring Boot)

转载 作者:行者123 更新时间:2023-12-01 19:58:46 28 4
gpt4 key购买 nike

我正在尝试使用基于 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>

关于java - 发布 Apache CXF 服务时出现异常(java 配置,无 Spring Boot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59018916/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com