Grails 3 - change default port for run-app

前端 未结 4 1732
野的像风
野的像风 2020-12-16 10:16

In Grails3 grails -Dserver.port=9001 run-app doesn\'t appear to work:

I\'m \"getting address already bound 8080\".

相关标签:
4条回答
  • 2020-12-16 10:31

    You can use

    server:
      port: 9001
    

    in application.yml.

    Or you can pass it via system environment. (e.g. SERVER_PORT=9001 grails run-app).

    0 讨论(0)
  • 2020-12-16 10:39
    grails run-app --port=8081
    

    Or in interactive mode:

    run-app --port=8081
    

    Don't forget to use the same port when you want to stop the server:

    stop-app --port=8081
    

    I believe this feature was broken in 3.0.3 and earlier versions but it definitely works in 3.0.4.

    0 讨论(0)
  • 2020-12-16 10:45

    Accepted answer is correct. For some additional info, Grails 3 uses spring-boot and the server properties are configured by the

    org.springframework.boot.autoconfigure.web.ServerProperties
    

    class. "port" is just a property on this class which is filled from the application.yml with the prefix "server". So in addition to the port, you can set properties of this class including tomcat configuration properties and etc. To change the contextPath for instance you add

    server: 
       contextPath: /myapp
    

    to you application.yml.

    0 讨论(0)
  • 2020-12-16 10:50
      server:
      port: 9809
      contextPath: '/admin/'
    

    you can use this in your application.yml file

    or change the port depends on the environment for example :

        environments:
            test:
                grails:
                    serverURL: "http://localhost:9809"
    
    0 讨论(0)
提交回复
热议问题