在不更改代码的情况下更改 Spring Boot 应用程序的端口 [英] Change the port of a Spring boot application without changing the code

查看:35
本文介绍了在不更改代码的情况下更改 Spring Boot 应用程序的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个应用程序需要同时运行,并且都试图在端口 8080 上运行.我想将其中之一更改为端口 9000.我要更改的应用程序具有 spring 安全性,因此在使用 https 时在端口 8443 上运行,在使用 时在端口 8080 上运行http.我必须从端口 8080 移动它而不更改任何 .java 文件.此外,我还需要在端口 8080 上运行其他应用程序,因此更改默认的 tomcat 端口不是一个好主意.

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.

我尝试向 application.properties 添加行 server.port=9000, spring.main.server.port=9000,然后运行 mvn install,然后运行 ​​java -jar target/app.jar.

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.

我还尝试使用不同的标志运行 java -jar target/app.jar:-Dserver.port=9000--server.port=9000.

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

无论如何,我得到 - Tomcat 在端口上启动:8443 (https) 8080 (http).

所以,我的问题是:

  • 如何让它在不同于 8080 的端口上运行?
  • 还有,什么可能导致配置文件不更改端口?

推荐答案

运行以下命令:

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

将以下 plugin 添加到您的 pom.xml 文件

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>

这篇关于在不更改代码的情况下更改 Spring Boot 应用程序的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆