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


当前回答

正如大家所说,您可以在application.properties中指定 服务器。Port = 9000(可以是任何其他值) 如果您在项目中使用弹簧执行器,默认情况下它指向 8080,如果你想改变它,在应用程序中。属性提 管理。Port = 9001(可以是任何其他值)

其他回答

希望这篇文章能有所帮助

application.properties=> 

server.port=8090

application.yml=> 

server
  port:8090

默认端口号是:8080,但我们可以在application.properties中自定义端口号 如下图所示

spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
server.port = 5050 -- #here we can give any port number.

在应用程序中。资源中的属性文件:

server.port=8082

将此添加到应用程序中。属性文件

server.port= 8080

通过编程方式,使用spring boot 2.1.5:

import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;

@Component
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

    @Override
    public void customize(ConfigurableServletWebServerFactory server) {
        server.setPort(9000);
    }

}