springboot啟動為什么總是說端口被占用
springboot啟動為什么總是說端口被占用
紫衣仙女
2019-02-19 13:13:54
TA貢獻2036條經驗 獲得超8個贊
web服務器的端口在Spring Boot中是以server.port這個屬性存在的,以下方法都可以推而廣之到任何屬性:
修改Spring Boot應用類路徑上的application.properties文件,設置server.port=1234,1234就是你想要的端口。
在啟動Spring Boot應用的命令行參數(也就是JVM參數中)加入-Dserver.port=1234
利用@Configuration配置Tomcat容器:
@Configurationpublic class ServletConfig { @Bean
public EmbeddedServletContainerCustomizer containerCustomizer() { return (container -> {
container.setPort(1234);
});
}
}
也可以利用Java的System Properties來設置:
System.getProperties().put( "server.port", 1234 );
SpringApplication.run(App.class, args);
舉報