解決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:UsersAdministrator.m2repositoryorgapachetomcatembed
講該目錄下的所有文件刪除,然后右鍵項目maven-> update project,
其他同類發現classNotFound也可以通過尋找對應jar包在本地倉庫位置,使用相同操作進行解決
補充知識:springboot 設置web和非web啟動
springBoot區分web和非web項目
老版本:
#server config#web_environment是否是web項目spring.main.web_environment=true#是否加載springboot bannerspring.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不啟動問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。
相關文章: