JAVA springboot如何開啟倆端口
JAVA springboot開啟倆端口
- 應(yīng)用場(chǎng)景:
- 微信小程序,需要一個(gè)https端口,正常后臺(tái)是http端口
1.修改配置文件(.yml)
# 開發(fā)環(huán)境配置 server: # 服務(wù)器的HTTP端口,默認(rèn)為8080 port: 8080 # 新增開始 # https證書配置,不寫就是倆http端口 # 證書放到 src/main/resources ssl: key-store: classpath:證書名.pfx key-alias: alias key-store-password: 秘鑰 key-store-type: PKCS12 # 新增結(jié)束 servlet: # 應(yīng)用的訪問路徑 context-path: / tomcat: # tomcat的URI編碼 uri-encoding: UTF-8 # 連接數(shù)滿后的排隊(duì)數(shù),默認(rèn)為100 accept-count: 1000 threads: # tomcat最大線程數(shù),默認(rèn)為200 max: 800 # Tomcat啟動(dòng)初始化的線程數(shù),默認(rèn)值10 min-spare: 100 # 新增,可以不加,新端口可以直接寫到啟動(dòng)類里面 http: # 新加一個(gè)http的端口號(hào)配置 port: 8081
2.修改啟動(dòng)類(XxApplication)
package com.xx; import org.apache.catalina.connector.Connector; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; /** * 啟動(dòng)程序 * * @author */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) public class XxApplication { //新增開始 @Value("${http.port}") private Integer port; @Bean public ServletWebServerFactory servletContainer() { TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http return tomcat; } // 配置http private Connector createStandardConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setPort(port); return connector; } //新增結(jié)束 public static void main(String[] args) { // System.setProperty("spring.devtools.restart.enabled", "false"); SpringApplication.run(XskApplication.class, args); } }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
MybatisPlus插件自動(dòng)維護(hù)更新和創(chuàng)建時(shí)間方式
這篇文章主要介紹了MybatisPlus插件自動(dòng)維護(hù)更新和創(chuàng)建時(shí)間方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04elasticsearch數(shù)據(jù)信息索引操作action?support示例分析
這篇文章主要為大家介紹了elasticsearch數(shù)據(jù)信息索引操作action?support示例分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04Java實(shí)現(xiàn)學(xué)生選課管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)學(xué)生選課管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07如何為Spring Cloud Gateway加上全局過濾器
這篇文章主要介紹了如何為Spring Cloud Gateway加上全局過濾器,幫助大家更好得理解和學(xué)習(xí)使用Gateway,感興趣的朋友可以了解下2021-03-03SpringBoot接口正確接收時(shí)間參數(shù)的幾種方式
這篇文章主要給大家介紹了關(guān)于SpringBoot接口正確接收時(shí)間參數(shù)的相關(guān)資料,文中通過代碼示例介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用springboot具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09Kotlin常用函數(shù)let,with,run,apply用法與區(qū)別案例詳解
這篇文章主要介紹了Kotlin常用函數(shù)let,with,run,apply用法與區(qū)別案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-09-09List轉(zhuǎn)變?yōu)槎禾?hào)分隔的String(Java7和Java8分別實(shí)現(xiàn))
這篇文章主要介紹了Java7和Java8分別實(shí)現(xiàn)List轉(zhuǎn)變?yōu)槎禾?hào)分隔的String,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06