简体   繁体   English

在guice模块中获取运行Play微服务的端口

[英]Get Port of running play microservice within a guice module

I'd like to start a play application at a random port (port 0). 我想在一个随机端口(端口0)上启动一个播放应用程序。 Each started microservice instance should connect to a service locator (eureka) and tell him his port and host. 每个启动的微服务实例都应连接到服务定位器(eureka),并告诉他他的端口和主机。 But how can I retrieve the port of a running play service? 但是,如何获取正在运行的播放服务的端口?

This question was actually asked several times, but the answers did not work for me: 这个问题实际上被问过几次,但是答案对我不起作用:

class MyModule @Inject() (configuration: Configuration) extends AbstractModule {
  configuration.getInt("http.port") // returns None
  System.getProperty("http.port") // returns null
}

根据播放文档,这应该起作用:

configuration.get[Int]("play.server.http.port")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM