如何在 sparkjava 上配置 host/ip?

How do I configure host/ip on sparkjava?

如果我的服务器上有多个 IP 地址,并且想将每个 spark 应用分配给不同的 IP address/host,这是怎么做到的?

Spark Service class (javadoc) 中有一个方法可以设置您的 Spark 服务器侦听的 IP 地址。

public Service ipAddress(String ipAddress)

Set the IP address that Spark should listen on. If not called the default address is '0.0.0.0'. This has to be called before any route mapping is done.


如果您希望这些应用程序 运行 在同一个 JVM 中,看起来您可以通过实例化多个 Service onject 来实现。 javadoc 说:

Service represents a Spark server "session". If a user wants multiple 'Sparks' in his application the method ignite() should be statically imported and used to create instances.

使用Spark.ipAddress("my.IP.address");
参考:javadoc