0
如何獲取Play應用程序中的當前端口號?我使用scala。這裏下面Play Framework:如何獲取當前端口號
如何獲取Play應用程序中的當前端口號?我使用scala。這裏下面Play Framework:如何獲取當前端口號
是我的解決方案:
def localHost()(implicit request: RequestHeader = null): Host = {
def loadFromConfig = {
val ssl = config.getBoolean("ssl").getOrElse(false)
val host = config.getString("host").getOrElse(EndPoint.DefaultHostName)
val port = Play.isTest match {
case false => System.getProperty("http.port", null) match {
case port if port != null => parse[Int](port).getOrElse(EndPoint.DefaultPort)
case _ => EndPoint.DefaultPort
}
case _ => System.getProperty("testserver.port", null) match {
case port if port != null => parse[Int](port).getOrElse(EndPoint.DefaultTestPort)
case _ => EndPoint.DefaultTestPort
}
}
Host(EndPoint(host, port), ssl)
}
request match {
case null => if (_localHost == null) this.synchronized {
if (_localHost == null) _localHost = loadFromConfig
}
_localHost
case _ => Host(EndPoint(Some(request.host)), request.secure)
}
}
我希望它能幫助。
你試過嗎?:http://stackoverflow.com/questions/14970677/retrieving-port-number-in-play-framework-2-app – Identity1
什麼是您使用的Playframework的版本? –
我正在使用Play 2.3.8 – j3d