首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache + SpringBoot:我可以为一个SOAP web服务发布多个端点吗?

Apache + SpringBoot:我可以为一个SOAP web服务发布多个端点吗?
EN

Stack Overflow用户
提问于 2018-02-14 00:51:10
回答 1查看 3.6K关注 0票数 3

我使用Apache + SpringBoot实现了一个SOAP。

在我的端点配置类中,我有

代码语言:javascript
复制
@Bean
public Endpoint endpoint()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl());
    endpoint.publish("/myservice");
    return endpoint;
}

这将将web服务端点创建为https://host:port/myService

对于此服务,我需要公开多个端点-类似于- https://host:port/tenant1/myService

https://host:port/tenant2/myService

https://host:port/tenant3/myService

这是一种REST端点--也就是说,我试图在服务端点中传递tenantId变量。

这在Apache + Springboot中是可能的吗?

我试过这个-

代码语言:javascript
复制
@Bean
public Endpoint endpoint()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl()); 
    String[] pathArray = {"tenant1", "tenant2", "tenant3"};
    for (int i = 0; i < pathArray.length; i++)
    {
        endpoint.publish("/" + pathArray[i] + "/myservice");
    }
    return endpoint;
}

但不起作用。

如有任何意见或建议,我将不胜感激。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-14 06:04:40

不,不能有相同的端点映射到多个urls,一个端点是为一个wsdl文件创建的,该文件将生成到单个类。从url中,我假设您希望基于租户在多个url上承载相同的服务。在这种情况下,您必须为每个租户创建端点。

代码语言:javascript
复制
@Bean
public Endpoint endpoint1()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl()); 
    endpoint.publish("/tenant1/" + pathArray[i] + "/myservice");
    return endpoint;
}

@Bean
public Endpoint endpoint2()
{
    EndpointImpl endpoint = new EndpointImpl(cxfBus, new ServiceImpl()); 
    endpoint.publish("/tenant1/" + pathArray[i] + "/myservice");
    return endpoint;
}

代码语言:javascript
复制
@Configuration
public class CxfConfiguration implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {

        Arrays.stream(new String[] { "tenant1", "tenant2" }).forEach(str -> {
            Bus bus = factory.getBean(Bus.class);
            JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();
            bean.setAddress("/" + str + "/myService");
            bean.setBus(bus);
            bean.setServiceClass(HelloWorld.class);
            factory.registerSingleton(str, bean.create());
        });

    }


}

顺便问一下:休息可能是更好的方式吗?

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48778052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档