spring boot如何指定啟動端口
這篇文章主要介紹了spring boot如何指定啟動端口,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
spring boot 默認端口為8080
1.修改為指定端口
(1)修改配置文件
src/main/resources/application.properties
server.port=8081
(2)通過編碼的方式來指定端口
在啟動類中添加servletContainer方法
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.context.annotation.Bean; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } @Bean public TomcatServletWebServerFactory servletContainer(){ return new TomcatServletWebServerFactory(8081) ; } }
說明:
該代碼適用于spring boot2X中
2.動態(tài)指定端口
生成jar包后,動態(tài)指定端口
(1)在命令行中指定啟動端口
java -jar test.jar --server.port=8081
(2)傳入虛擬機系統(tǒng)屬性
java -Dserver.port=8081 -jar test.jar
說明:
java [options] -jar filename [args]
其中 options
-D[property]=value
定義系統(tǒng)屬性值
property變量是一個字符串代表屬性名,value代表設定的屬性值
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
StringUtils里的isEmpty方法和isBlank方法的區(qū)別詳解
這篇文章主要介紹了StringUtils里的isEmpty方法和isBlank方法的區(qū)別詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2020-04-04Mybatis-plus操作json字段實戰(zhàn)教程
這篇文章主要介紹了Mybatis-plus操作json字段實戰(zhàn)教程,本文結合實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-02-02使用SpringJPA?直接實現(xiàn)count(*)
這篇文章主要介紹了SpringJPA?直接實現(xiàn)count(*),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11