記一次項目啓動記錄

Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean。spring源碼。

報錯的位置org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#getWebServerFactory。

String[] beanNames = getBeanFactory()
      .getBeanNamesForType(ServletWebServerFactory.class);
if (beanNames.length == 0) {
   throw new ApplicationContextException(
         "Unable to start ServletWebServerApplicationContext due to missing "
               + "ServletWebServerFactory bean.");
}

這個報錯是因爲沒有找到內嵌的tomcat容器。由於pom文件是指定了範圍provided,在執行run這個springapp時不會將tomcat的jar包放到classpath,所以啓動會報這個錯誤。但是打包的時候一定要記得改回到provided。延伸一點,這個是從類路徑裏面找到實現了ServletWebServerFactory接口的類,如果你確定你引入了第三方的web容器jar但是還報這個錯,就要確認你的類路徑是不是的的確確引入了,同樣如果報錯是Unable to start ServletWebServerApplicationContext due to multiple,就是引入過多的web容器了。

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <!--<scope>provided</scope>-->
</dependency>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章