使用内置Java JAX-WS web服务器发布多个端点

使用内置Java JAX-WS web服务器发布多个端点,java,web-services,jax-ws,publish,built-in,Java,Web Services,Jax Ws,Publish,Built In,所以我有两个web服务接口类的实现,Impl1和Impl2。我想在相同的域和端口下发布,但使用不同的URL: 及 显然,我应该能够创建一个配置,其中我有两个端点,每个实现一个,绑定到一个web服务器实例 请注意,我不是在部署,而是在使用Java7内部发布机制。 我注意到他没有打电话 Endpoint.publish(URL, new Implementor()); 要直接发布web服务,我可以调用 Endpoint ep = Endpoint.create(new Implementor())

所以我有两个web服务接口类的实现,Impl1和Impl2。我想在相同的域和端口下发布,但使用不同的URL:

显然,我应该能够创建一个配置,其中我有两个端点,每个实现一个,绑定到一个web服务器实例

请注意,我不是在部署,而是在使用Java7内部发布机制。 我注意到他没有打电话

Endpoint.publish(URL, new Implementor());
要直接发布web服务,我可以调用

Endpoint ep = Endpoint.create(new Implementor());
ep.publish(serverContext);
在特定的serverContext上发布实现者。究竟什么是这样的serverContext?如何使用它?我注意到
publish
方法实例化了
javax.xml.ws.spi.Provider
类,并将其用于发布目的。但这显然不是我想要的。理想情况下,我想要一个类似以下内容的解决方案:

Object serverContext = new Server(URL);
Endpoint impl1 = Endpoint.create(new Impl1());
Endpoint impl2 = Endpoint.create(new Impl2());
impl1.publish(serverContext);
impl2.publish(serverContext);

甚至可以使用内置的发布系统(可能使用
EndpointReferences
对象)来实现这一点吗?或者我需要使用web服务容器单独部署端点吗?

使用以下代码可以实现发布在同一端口上运行的多个端点:

@SpringBootApplication
public class Application {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
    Endpoint.publish("http://localhost:8888/ws/send", new SendServiceImpl());
    Endpoint.publish("http://localhost:8888/ws/send23", new SendServiceImpl());
  } 
}
在Eclipse中本地运行此功能是可行的,但当您将其部署到另一台服务器时,它将被破坏。
要解决此问题,您可以使用而不是localhost或服务器的正确内部ip地址

您发现它正在运行: windows:ipconfig unix:ifconfig


它看起来像这样:192.168.100.55。

我今天偶然发现了这个问题;当将两个不同的端点发布到同一主机+端口时,我不断得到“java.net.BindException:Address ready in use”。解决方案是自己实例化
HttpServer
并将每个端点“绑定”到此服务器:

package mypackage;

import com.sun.net.httpserver.HttpServer;

import javax.xml.ws.Endpoint;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;

public static void main(String[] args) throws IOException {
    final HttpServer httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 8080), 16);

    final Endpoint fooEndpoint = Endpoint.create(new FooImpl());
    fooEndpoint.publish(httpServer.createContext("/Foo"));

    final Endpoint barEndpoint = Endpoint.create(new BarImpl());
    barEndpoint.publish(httpServer.createContext("/Bar"));

    httpServer.start();
}

如果你认为你链接的问题也可以回答这个问题,请将其标记为重复,不要将其链接为答案。我不能将其标记为重复,因为我的代表性很低。它不是重复的,答案不会令人满意。但我编辑了答案,因为我找到了一个很好的解决方案,即使在Eclipse中也不适用于我。异常为“java.net.BindException:Address ready in use”@Jian Chen然后您应该将端口从8888更改为您想要的任何端口。我得到错误“class sun.net.httpserver.HttpContextImpl不是受支持的上下文。”在运行时用于发布函数。