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)用程序的形式運(yùn)行。
除了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)用程序的運(yùn)行方式和行為。
到此這篇關(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實(shí)現(xiàn)服務(wù)器發(fā)送事件(Server-Sent Events)
- SpringBoot中的server.context-path的實(shí)現(xiàn)
- SpringBoot實(shí)現(xiàn)Server-Sent Events(SSE)的使用完整指南
- SpringBoot開啟server:compression:enabled(Illegal character ((CTRL-CHAR, code 31)))的問題解決
相關(guān)文章
spring boot actuator監(jiān)控超詳細(xì)教程
Spring Boot Actuator就是一款可以幫助你監(jiān)控系統(tǒng)數(shù)據(jù)的框架,其可以監(jiān)控很多很多的系統(tǒng)數(shù)據(jù),接下來通過本文給大家介紹spring boot actuator監(jiān)控超詳細(xì)教程,感興趣的朋友一起看看吧2021-10-10Java編程在ICPC快速IO實(shí)現(xiàn)源碼
這篇文章主要介紹了Java Fast IO in ICPC實(shí)現(xiàn)源碼,具有一定參考價值,需要的朋友可以了解下。2017-09-09SpringBoot靜態(tài)方法調(diào)用Spring容器bean的三種解決方案
在SpringBoot中靜態(tài)方法調(diào)用Spring容器bean時出現(xiàn)的null值問題,本文就來介紹一下SpringBoot靜態(tài)方法調(diào)用Spring容器bean的三種解決方案,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-01-01利用java監(jiān)聽器實(shí)現(xiàn)在線人數(shù)統(tǒng)計
過去使用ASP和ASP.NET兩種編程的時候,都寫過在線人數(shù)統(tǒng)計能,實(shí)現(xiàn)功能挺簡單的!今天使用java來實(shí)現(xiàn)在線人數(shù)統(tǒng)計有點(diǎn)另類,是通過Java監(jiān)聽器實(shí)現(xiàn)的,需要的朋友可以參考下2015-09-09