spring boot如何指定啟動(dòng)端口
這篇文章主要介紹了spring boot如何指定啟動(dòng)端口,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
spring boot 默認(rèn)端口為8080
1.修改為指定端口
(1)修改配置文件
src/main/resources/application.properties
server.port=8081
(2)通過編碼的方式來指定端口
在啟動(dòng)類中添加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.動(dòng)態(tài)指定端口
生成jar包后,動(dòng)態(tài)指定端口
(1)在命令行中指定啟動(dòng)端口
java -jar test.jar --server.port=8081
(2)傳入虛擬機(jī)系統(tǒng)屬性
java -Dserver.port=8081 -jar test.jar
說明:
java [options] -jar filename [args]
其中 options
-D[property]=value
定義系統(tǒng)屬性值
property變量是一個(gè)字符串代表屬性名,value代表設(shè)定的屬性值
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
StringUtils里的isEmpty方法和isBlank方法的區(qū)別詳解
這篇文章主要介紹了StringUtils里的isEmpty方法和isBlank方法的區(qū)別詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2020-04-04Mybatis-plus操作json字段實(shí)戰(zhàn)教程
這篇文章主要介紹了Mybatis-plus操作json字段實(shí)戰(zhàn)教程,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-02-02使用SpringJPA?直接實(shí)現(xiàn)count(*)
這篇文章主要介紹了SpringJPA?直接實(shí)現(xiàn)count(*),具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-11-11