解決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不啟動問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。