關於idea中SpringBoot啟動失敗的坑


很多時候你新建了Maven 或者SpringBoot 工程,激動的點了主啟動類,你就發現了下面的錯誤

 

 

 Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: 
Error creating bean with name 'servletEndpointRegistrar' defined in class path resource
[org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$
WebMvcServletEndpointManagementContextConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]:
Factory method 'servletEndpointRegistrar' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'healthEndpoint' defined in class path resource
[org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]:
Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'healthContributorRegistry' defined in class path resource
[org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]:
Factory method 'healthContributorRegistry' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration':
Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]:
Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:
Failed to determine a suitable driver class [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException:
Unable to start embedded Tomcat --- [ restartedMain] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-09-03 13:12:04.338 ERROR 24572 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class Action: Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

  這里說的是啥意思呢,你沒有數據庫相關的鏈接,數據庫相關的鏈接在哪里配置呢,就是在你的Resource文件目錄下的properties 或者yml文件中

但是這里你可能會說,我**不用數據庫,我干啥配這個b玩意,我想說這句話的時候,你已經點了很多遍的主啟動都報這個錯誤,

今天你算來對了,我敢肯定80%的人都遇到過這個問題。但是不知道為啥,今天我給你分析一下昂:

①:在IDEA 中用SpringInitial  點點點生成的SpringBoot/cloud項目
②:跟視頻操作,一頓操作后發現不能啟動,
③:DonwLoad下的代碼   復制進去的POM依賴

還有很多昂,不墨跡了說重點吧。
解決方法:

首先着重看自己的POM依賴(是自己的POM,不是父工程,也不是其他工程,是自己的)中有無以下依賴

 

 

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql.version}</version>
</dependency>

  

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

  經過鄙人的測試,就是第一個依賴搗的鬼,這就是為啥你加了這個依賴你不配置相關的mysql鏈接,Spring就給你報錯的原因。

 

 

最后提醒:按需注入POM才是正道,老鐵們,我做的對么?


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM