1
有一個關於更改Play應用程序綁定到的HTTP端口的常見問題。 James Ward's answer通常被認爲是最完整的,但它涉及通過設置http.port
系統屬性來覆蓋默認值。但是,是否可以更改此默認值,而無需在開發時手動將其添加到run
命令中,調整環境或在運行時配置中打包重寫?更改默認播放框架HTTP端口(不使用系統屬性)
有一個關於更改Play應用程序綁定到的HTTP端口的常見問題。 James Ward's answer通常被認爲是最完整的,但它涉及通過設置http.port
系統屬性來覆蓋默認值。但是,是否可以更改此默認值,而無需在開發時手動將其添加到run
命令中,調整環境或在運行時配置中打包重寫?更改默認播放框架HTTP端口(不使用系統屬性)
這可以通過設置playDefaultPort
key來完成,如下所示:
import PlayKeys._
playDefaultPort := 9123
之後,您就可以run
和testProd
無需記住所需的端口。
這個工作在兩種發展:
$ sbt run
[info] Loading project definition from /Users/michaelahlers/Projects/MyApp/project
[info] Set current project to MyApp (in build file:/Users/michaelahlers/Projects/MyApp/)
--- (Running the application, auto-reloading is enabled) ---
[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9123
(Server started, use Ctrl+D to stop and go back to the console...)
和生產模式:
$ sbt testProd
[info] Loading project definition from /Users/michaelahlers/Projects/MyApp/project
[info] Set current project to MyApp (in build file:/Users/michaelahlers/Projects/MyApp/)
[info] Packaging /Users/michaelahlers/Projects/MyApp/target/scala-2.11/MyApp_2.11-1.0.0-SNAPSHOT-web-assets.jar ...
[info] Done packaging.
(Starting server. Type Ctrl+D to exit logs, the server will remain in background)
2016-04-08 13:09:45,594 [info] a.e.s.Slf4jLogger - Slf4jLogger started
2016-04-08 13:09:45,655 [info] play.api.Play - Application started (Prod)
2016-04-08 13:09:45,767 [info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9123