SpringBoot服務(wù)設(shè)置禁止server.point端口的使用
問題:
當(dāng)項目服務(wù)引用了jar spring-boot-starter-web后
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
所以項目一啟動,就會使用server.point端口
如果沒有配置 server.port 也會默認(rèn)去找8080
解決辦法:
方法1.
在配置文件加上:
spring:
main:
allow-bean-definition-overriding: true
web-application-type: none
方法2:
在啟動類設(shè)置 setWebApplicationType
public static void main(String[] args) {
try {
SpringApplication app = new SpringApplication(TestApplication.class);
app.setWebApplicationType(WebApplicationType.NONE);
app.setBannerMode(Banner.Mode.CONSOLE);
app.setBanner(new ResourceBanner(new ClassPathResource("config/banner.txt")));
app.run(args);
} catch (Exception e) {
e.printStackTrace();
}
}
或
public static void main(String[] args) {
new SpringApplicationBuilder(Application .class)
.web(WebApplicationType.NONE)
.run(args);
}
setWebApplicationType是Spring Framework中的方法,用于設(shè)置Web應(yīng)用程序的類型。在Spring Boot中,可以通過這個方法來指定應(yīng)用程序的類型,例如Servlet、Reactive或None。
在Spring Boot中,可以使用setWebApplicationType方法來設(shè)置應(yīng)用程序的類型。這個方法通常在SpringApplication類的main方法中調(diào)用,用于指定應(yīng)用程序的類型。
通過setWebApplicationType方法將Web應(yīng)用程序類型設(shè)置為Servlet。這樣可以確保Spring Boot應(yīng)用程序?qū)⒁許ervlet應(yīng)用程序的形式運行。
除了WebApplicationType.SERVLET,還有WebApplicationType.REACTIVE和WebApplicationType.NONE這兩個選項,分別用于設(shè)置Web應(yīng)用程序類型為Reactive和無Web應(yīng)用程序(即非Web應(yīng)用程序)。
總之,setWebApplicationType方法是用于在Spring Boot中設(shè)置Web應(yīng)用程序類型的重要方法,它可以影響應(yīng)用程序的運行方式和行為。
到此這篇關(guān)于SpringBoot服務(wù)設(shè)置禁止server.point端口的使用的文章就介紹到這了,更多相關(guān)SpringBoot禁止server.point端口內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- springboot整合websocket后啟動報錯(javax.websocket.server.ServerContainer not available)
- springboot中server.ssl.key-store配置路徑的問題小結(jié)
- 使用Java和SpringBoot實現(xiàn)服務(wù)器發(fā)送事件(Server-Sent Events)
- SpringBoot中的server.context-path的實現(xiàn)
- SpringBoot實現(xiàn)Server-Sent Events(SSE)的使用完整指南
- SpringBoot開啟server:compression:enabled(Illegal character ((CTRL-CHAR, code 31)))的問題解決
相關(guān)文章
Java與Scala創(chuàng)建List與Map的實現(xiàn)方式
這篇文章主要介紹了Java與Scala創(chuàng)建List與Map的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-10-10
Java中方法優(yōu)先調(diào)用可選參數(shù)還是固定參數(shù)
這篇文章主要介紹了Java中方法優(yōu)先調(diào)用可選參數(shù)還是固定參數(shù),可選參數(shù)是?JDK?5?中新增的特性,也叫變長參數(shù)或可變參數(shù),固定參數(shù)的概念恰好與可選參數(shù)相反,固定參數(shù)也就是普通的參,下文更多詳細(xì)內(nèi)容需要的小伙伴可以參考一下2022-05-05
SpringBoot使用Filter實現(xiàn)簽名認(rèn)證鑒權(quán)的示例代碼
這篇文章主要介紹了SpringBoot使用Filter實現(xiàn)簽名認(rèn)證鑒權(quán)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
SpringBoot從Nacos讀取MySQL數(shù)據(jù)庫配置錯誤:Public Key Retrieva
最近的項目,突然都從MySQL5.7升級到8.0了,有些項目能運行成功,有些項目遇到了問題,啟動不成功,顯示數(shù)據(jù)庫方面的異常信息,本文給大家介紹了SpringBoot從Nacos讀取MySQL數(shù)據(jù)庫配置錯誤:Public Key Retrieval is not allowed的解決方案,需要的朋友可以參考下2024-04-04

