解決Spring boot 嵌入的tomcat不啟動問題
此文章記錄一次spring boot通過main 方法啟動無法成功的問題
Unregistering JMX-exposed beans on shutdown
問題如下,因為已經(jīng)解決用的別人的截圖但是效果是一樣的

百度了一圈都說tomcat沒有配置,但實際xml有如下配置
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency>
問題:eclipse maven自動下jar包時下載的不全,有部分文件丟失,但是控制臺并沒有發(fā)出任何 classNotFound提示
解決:C:\Users\Administrator\.m2\repository\org\apache\tomcat\embed
講該目錄下的所有文件刪除,然后右鍵項目maven-> update project,
其他同類發(fā)現(xiàn)classNotFound也可以通過尋找對應(yīng)jar包在本地倉庫位置,使用相同操作進行解決
補充知識:springboot 設(shè)置web和非web啟動
springBoot區(qū)分web和非web項目
老版本:
#server config #web_environment是否是web項目 spring.main.web_environment=true #是否加載springboot banner spring.main.show_banner=false
現(xiàn)版本:
#server config #是否設(shè)定web應(yīng)用,none-非web,servlet-web應(yīng)用 spring.main.web-application-type=servlet #加載springboot banner的方式:off-關(guān)閉,console-控制臺,log-日志 spring.main.banner-mode=off
WebApplicationType原理:
public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
this.resourceLoader = resourceLoader;
Assert.notNull(primarySources, "PrimarySources must not be null");
this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));
this.webApplicationType = deduceWebApplicationType();
setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));
setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
this.mainApplicationClass = deduceMainApplicationClass();
}
deduceWebApplicationType()推斷當(dāng)前環(huán)境是哪種Web環(huán)境(Servlet、Reactive),或者不是Web環(huán)境,判斷邏輯為Classpath是夠有以下類:
存在org.springframework.web.reactive.DispatcherHandler且不存在org.springframework.web.servlet.DispatcherServlet為WebApplicationType.REACTIVE;
同時存在javax.servlet.Servlet、org.springframework.web.context.ConfigurableWebApplicationContext 為WebApplicationType.SERVLET;
否則為 WebApplicationType.NONE
在這里this.webApplicationType = WebApplicationType.SERVLET;
所謂的banner就是控制臺打印的一堆線組成的spring

以上這篇解決Spring boot 嵌入的tomcat不啟動問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
springboot下實現(xiàn)RedisTemplate?List?清空
我們經(jīng)常會使用Redis的List數(shù)據(jù)結(jié)構(gòu)來存儲一系列的元素,當(dāng)我們需要清空一個List時,可以使用RedisTemplate來實現(xiàn),本文就來詳細(xì)的介紹一下如何實現(xiàn),感興趣的可以了解一下2024-01-01
springboot3整合SpringSecurity實現(xiàn)登錄校驗與權(quán)限認(rèn)證
本文主要介紹了springboot3整合SpringSecurity實現(xiàn)登錄校驗與權(quán)限認(rèn)證,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2025-04-04
Java關(guān)于后端怎么去接收Date、LocalDateTime類型的參數(shù)詳解
這篇文章主要介紹了java關(guān)于后端怎么去接收Date、LocalDateTime類型的參數(shù),文中有詳細(xì)的代碼流程,對我們學(xué)習(xí)或工作有一定的參考價值,需要的朋友可以參考下2023-06-06
Java+EasyExcel實現(xiàn)文件的導(dǎo)入導(dǎo)出
在項目中我們常常需要Excel文件的導(dǎo)入與導(dǎo)出,手動輸入相對有些繁瑣,所以本文教大家如何在Java中輕松導(dǎo)入與導(dǎo)出Excel文件,感興趣的可以學(xué)習(xí)一下2021-12-12

