简体   繁体   中英

Java Play overwrites port in application.conf

I want to specify port on which Java Play exposes its endpoints in the application.conf file – complete snippet of the application.conf , format taken from Java Play documentation

play.server.http.port = 5511

However, if I run command

  • sbt run

exposed port is 9000, not 5511.

I was able to achieve correct behaviour by running

  • sbt run -Dhttp.port=5511

so there must be problem in the application.conf . If I try to read the value programmatically, say from controller, it also gets the wrong value of 9000. However, if I add some artificial value to the application.conf , say foo = "ABC" , it correctly reads this value.


Java play version: 2.8.15
SBT version: 1.6.2
Plugins: only java play

As per of the play documentation :

In run mode the HTTP server part of Play starts before the application has been compiled. This means that the HTTP server cannot access the application.conf file when it starts. If you want to override HTTP server settings while using the run command you cannot use the application.conf file

I would propose you do this way sbt run -Dhttp.port=5511 as you stated earlier. If you are worried about passing everytime the arguments with run task then you can change your root project settings in the build.sbt file only once. Do not forget to to sbt reload so your build.sbt changes take effect.

lazy val root = (project in file(".")).enablePlugins(PlayJava)
   .settings(PlayKeys.playDefaultPort := 5511)

Another alternative : you can add the following line in your build.sbt file

PlayKeys.devSettings += "play.server.http.port" -> "8080"

I have no direct explanations, but that's work if you put on your application.conf file the http.port variable, and not directly play.server.http.port .

A clue may be found in the file, on Production Configuration page , presented by

The configurations above are specific to the Akka HTTP and Netty server backend

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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