如何为Spring Boot应用程序配置端口

1059

如何配置Spring Boot应用程序监听的TCP/IP端口,以便不使用默认的8080端口。


12
如果有人感兴趣,这里展示了如何有多个端口-https://dev59.com/GVoV5IYBdhLWcg3wXNs9 - Betlista
如果您使用“yml”文件进行配置,则可以使用以下内容: server: port: 8081 同时,将您的主类注释为“@SpringBootApplication”,并删除“@EnableAutoConfiguration”。 - Keaz
你的项目[application.properties]中添加以下内容: server.port=8080 - Lahiru Samishka
在应用程序属性中设置server.port=8080。此配置位于org.springframework.boot.autoconfigure.web下的ServerProperties.class类中。 - Atif
64个回答

0

在配置文件或应用程序属性中配置端口详细信息。

例如:

port =8876

0
这是一个在代码中设置端口的 Kotlin 方法:
fun main(args: Array<String>) {
    runApplication<TestApplication>(*args) {
        setDefaultProperties(mapOf(
            "server.port" to 8081
        ))
    }
}

-1
将以下代码放入您的application.properties文件中:
在此输入图像描述

文件名不正确。 - undefined

-3

在我的情况下添加语句

server.port=${port:8081}

覆盖默认的Tomcat服务器端口。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接