如何解决Apache CXF如何在构建码头服务器中安装的tomcat上部署/运行SOAP服务
如何在tomcat而非Jetty服务器上部署 CXF SOAP Web服务
如果我尝试使用tomcat端口运行ServerFactoryBean
,则显示错误:
端口已在运行。
是否可以使用tomcat代替内置码头服务器?
以下是我尝试创建服务器的代码。
SoapBindingFactory bindingFactory = new SoapBindingFactory();
Bus bus = BusFactory.newInstance().createBus();
bindingFactory.setBus(bus);
bus.getExtension(BindingFactoryManager.class).registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/",bindingFactory);
bus.getExtension(BindingFactoryManager.class).registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/http",bindingFactory);
Service service = new WSDLServiceFactory(bus,"wsdl path here",null).create();
ServerFactoryBean serverFactory = new ServerFactoryBean();
serverFactory.setBus(bus);
InboundRMHttpInvoker invoker = new InboundRMHttpInvoker(serviceImpl);
serverFactory.setInvoker(invoker);
serverFactory.setServiceBean(serviceImpl);
serverFactory.setDataBinding(service.getDataBinding());
serverFactory.setServiceName(service.getName());
serverFactory.setBindingId(service.getServiceInfos().get(0).getBindings().iterator().next().getBindingId());
serverFactory.setWsdlLocation("wsdl path");
serverFactory.setEndpointName(service.getServiceInfos().iterator().next().getEndpoints().iterator().next().getName());
serverFactory.setAddress("http://localhost:8080/services/sampleservice");
Server server = serverFactory.create();
如果我使用其他端口(tomcat除外),它将在该端口上部署我的服务,但是如何在tomcat端口上运行它。
解决方法
您可以考虑使用Spring Boot或类似程序开发应用程序。当您在应用程序容器(例如tomcat)中部署战争时,将使用容器中配置的端口。
更新
- 配置主类。
@SpringBootApplication
public class AwesomeApp extends SpringBootServletInitializer {
public static void main(String[] args) {
new SpringApplicationBuilder(AwesomeApp.class)
.run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(AwesomeApp.class);
}
}
- 在
@Configuration
类中配置CXF Servlet。
@Configuration
public class ServletConfig implements WebMvcConfigurer {
public ServletRegistrationBean<CXFServlet> cxfServletRegistration() {
ServletRegistrationBean<CXFServlet> bean = new ServletRegistrationBean<>(
new CXFServlet(),"/services/*");
bean.setLoadOnStartup(1);
return bean;
}
}
-
实施服务。
-
在
@Configuration
类中配置端点并注册实现。
@Configuration
public class IntegrationConfig {
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean(name = "awesomeServiceImpl")
public AwesomeServiceImpl awesomeServiceImpl() {
return new AwesomeServiceImpl();
}
@Bean
public Endpoint awesomeEndpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(),awesomeServiceImpl());
endpoint.publish("/awesomeService");
return endpoint;
}
}
- 运行您的应用并浏览到
/services/awesomeService
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。