JAVA springboot如何開啟倆端口
更新時(shí)間:2025年03月27日 10:09:16 作者:Aa_duidui
這篇文章主要介紹了JAVA springboot如何開啟倆端口問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
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: 80812.修改啟動(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)文章
Spring MVC學(xué)習(xí)教程之RequestMappingHandlerAdapter詳解
這篇文章主要給大家介紹了關(guān)于Spring MVC學(xué)習(xí)教程之RequestMappingHandlerAdapter的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11
J2ee 高并發(fā)情況下監(jiān)聽器實(shí)例詳解
這篇文章主要介紹了J2ee 高并發(fā)情況下監(jiān)聽器實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-02-02
詳解Spring與Mybatis的整合方法(基于Eclipse的搭建)
這篇文章主要介紹了Spring與Mybatis的整合方法(基于Eclipse的搭建),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
java執(zhí)行SQL語句實(shí)現(xiàn)查詢的通用方法詳解
這篇文章主要介紹了java執(zhí)行SQL語句實(shí)現(xiàn)查詢的通用方法詳解,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12

