(Java)同时发布WebService端点和HttpServer?
我能够独立地运行(Java)同时发布WebService端点和HttpServer?,java,web-services,httpserver,Java,Web Services,Httpserver,我能够独立地运行WebService和httpServer,但是当我同时运行这两种服务时,web服务wsdlurl就不再工作了。我希望这样做,这样我就可以从javascript调用web服务到相同的URL,而不会出现跨源问题 这可能吗 public class Main { public static void main(String[] args) throws Exception { int port = 8888; /* This works wit
WebService
和httpServer
,但是当我同时运行这两种服务时,web服务wsdl
url就不再工作了。我希望这样做,这样我就可以从javascript调用web服务到相同的URL,而不会出现跨源问题
这可能吗
public class Main {
public static void main(String[] args) throws Exception {
int port = 8888;
/* This works without httpServer running */
Endpoint.publish("http://localhost:" + port + "/ws/someService", new SomeService());
/* This works without Endpoint running */
HttpServer httpServer = HttpServer.create(new InetSocketAddress(port), 0);
httpServer.createContext("/someHandler", new SomeHandler());
}
}
尝试使用不同的端口。例如,如果对端点使用8888,则对HttpServer使用8890或其他东西 端点使用嵌入式HTTP服务器实现,该实现是Java的一部分。 因此,您实际上是在尝试在同一端口上使用两个不同的HTTP服务器,我认为这是行不通的。您应该使用不同的端口来实现此功能