這篇文章將為大家詳細講解有關Spring boot 嵌入的tomcat不啟動怎么解決,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
此文章記錄一次spring boot通過main 方法啟動無法成功的問題
Unregistering JMX-exposed beans on shutdown
問題如下,因為已經解決用的別人的截圖但是效果是一樣的

百度了一圈都說tomcat沒有配置,但實際xml有如下配置
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency>
問題:eclipse maven自動下jar包時下載的不全,有部分文件丟失,但是控制臺并沒有發出任何 classNotFound提示
解決:C:\Users\Administrator\.m2\repository\org\apache\tomcat\embed
講該目錄下的所有文件刪除,然后右鍵項目maven-> update project,
其他同類發現classNotFound也可以通過尋找對應jar包在本地倉庫位置,使用相同操作進行解決
補充知識:springboot 設置web和非web啟動
springBoot區分web和非web項目
老版本:
#server config #web_environment是否是web項目 spring.main.web_environment=true #是否加載springboot banner spring.main.show_banner=false
現版本:
#server config #是否設定web應用,none-非web,servlet-web應用 spring.main.web-application-type=servlet #加載springboot banner的方式:off-關閉,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()推斷當前環境是哪種Web環境(Servlet、Reactive),或者不是Web環境,判斷邏輯為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不啟動怎么解決就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。