
2018-11-21 19:43:12.076 WARN 5392 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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 2018-11-21 19:43:12.076 INFO 5392 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor' 2018-11-21 19:43:12.081 INFO 5392 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2018-11-21 19:43:12.122 INFO 5392 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-11-21 19:43:12.126 ERROR 5392 --- [ main] 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).
spring boot 會默認加載org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration這個類,而DataSourceAutoConfiguration類使用了@Configuration注解向spring注入了dataSource bean,又因為項目(eureka-server模塊和短信模塊)中並沒有關於dataSource相關的配置信息,所以當spring創建dataSource bean時因缺少相關的信息就會報錯。
解決辦法:
1、在@SpringBootApplication注解上加上exclude,解除自動加載DataSourceAutoConfiguration。
---------------------
作者:迷霧騎士
來源:CSDN
原文:https://blog.csdn.net/u010448530/article/details/80840828
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
@EnableEurekaServer
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}