Configuring the Server Port on Quarkus Applications – 配置Quarkus应用程序的服务器端口

最后修改: 2021年 7月 15日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

In this quick tutorial, we’re going to learn how to configure the server port on Quarkus applications.

在这个快速教程中,我们将学习如何配置Quarkus应用程序的服务器端口。

2. Configuring Port

2.配置端口

By default, similar to many other Java server applications, Quarkus listens to port 8080. In order to change the default server port, we can use the quarkus.http.port property.

默认情况下,与其他许多Java服务器应用程序类似,Quarkus监听端口为8080。为了改变默认的服务器端口,我们可以使用quarkus.http.port property。

Quarkus reads its configuration properties from various sources. Therefore, we can change the quarkus.http.port property from different sources, as well. For instance, we can make Quarkus listen to port 9000 by adding this to our application.properties:

Quarkus从各种来源读取其配置属性。因此,我们也可以从不同的来源改变quarkus.http.port属性。例如,我们可以通过在我们的application.properties中添加这个来使Quarkus监听9000端口。

quarkus.http.port=9000

Now, if we send a request to localhost:9000, the server would return some sort of an HTTP response:

现在,如果我们向localhost:9000发送一个请求,服务器将返回某种HTTP响应。

>> curl localhost:9000/hello
Hello RESTEasy

It’s also possible to configure the port through Java system properties and -D arguments:

也可以通过Java系统属性和-D参数来配置端口。

>> mvn compile quarkus:dev -Dquarkus.http.port=9000
// omitted
Listening on: http://localhost:9000

As shown above, the system property is overriding the default port here. In addition to these, we can use environment variables, too:

如上所示,系统属性在这里覆盖了默认的端口。除此以外,我们也可以使用环境变量。

>> QUARKUS_HTTP_PORT=9000 
>> mvn compile quarkus:dev

Here, we’re converting all characters in quarkus.http.port to uppercase and replacing dots with underscores to form the environment variable name.

在这里,我们要把quarkus.http.port中的所有字符转换为大写字母,并用下划线代替点,以形成环境变量名称

3. Conclusion

3.总结

In this short tutorial, we saw a couple of ways to configure the application port in Quarkus.

在这个简短的教程中,我们看到了在Quarkus中配置应用程序端口的几种方法。