Change the port of a Spring boot application without changing the code

孤街浪徒 提交于 2021-01-24 09:01:25

问题


I have two applications that I need to run simultaneously, and both are trying to run on port 8080. I'd like to change one of them to port 9000. The application I'm trying to change has spring security, so it runs on port 8443 when using https and port 8080 when using http. I have to move it from port 8080 without changing any .java files. Also, I need to run the other application on port 8080 as well, so changing the default tomcat port wouldn't be a good idea.

I tried adding to application.properties the lines server.port=9000, spring.main.server.port=9000, then running mvn install, and then java -jar target/app.jar.

I also tried running java -jar target/app.jar with different flags: -Dserver.port=9000 and --server.port=9000.

Regardless, I get - Tomcat started on port(s): 8443 (https) 8080 (http).

So, my questions are:

  • How do I get it to run on a port different from 8080?
  • And, what could be causing the configuration files to not change the port?

回答1:


Run the following command:

mvn spring-boot:run -Drun.jvmArguments='-Dserver.port=8088'

Add the following plugin to your pom.xml file

<build>
    . . . 
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>


来源:https://stackoverflow.com/questions/37215498/change-the-port-of-a-spring-boot-application-without-changing-the-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!