如何配置运行Quarkus应用程序的端口?

geo*_*and 7 quarkus

我希望我的Quarkus应用程序在默认端口以外的端口上运行。我该怎么做?

geo*_*and 11

所使用的Quarkus配置属性为quarkus.http.port(默认值为8080)。如果设置了此属性application.properties,则将使用该值。

也可以在运行时重写该属性,如下所示:

在JVM模式下运行Quarkus应用程序时,可以使用quarkus.http.port系统属性设置端口。例如:

java -Dquarkus.http.port=8081 -jar example-runner.java
Run Code Online (Sandbox Code Playgroud)

相同的属性适用于GraalVM纯模式图像。例如:

./example-runner -Dquarkus.http.port=8081
Run Code Online (Sandbox Code Playgroud)

  • @Tuelho还没有一个(但是有计划创建它)。您必须查看* Config类的源代码,例如https://github.com/quarkusio/quarkus/blob/0.14.0/extensions/undertow/runtime/src/main/java/io/quarkus/undertow /runtime/HttpConfig.java (2认同)
  • 如果需要覆盖默认的测试端口,请使用:quarkus.http.test-port = 8888我在Windows上运行测试时遇到了问题。 (2认同)

Jes*_*ick 5

为了补充 geoand 的答案,您可以对mvn quarkus:dev. 不幸的是,您不能直接在配置文件中设置它~/.m2/settings.xml以避免每次都需要输入它(例如因为Microk8s 绑定了 8080),但您可以通过jvm.args以下方式设置它:

<profiles>
    <profile>
        <id>microk8s-quarkus-dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <jvm.args>-Dquarkus.http.port=8090</jvm.args>
        </properties>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

或者,您可以在项目源中配置它:

echo '%dev.quarkus.http.port=8090' >> src/main/resources/application.properties
Run Code Online (Sandbox Code Playgroud)

尽管这不会在项目之间共享,并且同一项目的其他开发人员可能不需要。