啟動(dòng)程序出現(xiàn)以下錯(cuò)誤:
017-05-06 22:44:18.868 WARN 41648 --- [ restartedMain] ationConfigEmbeddedWebApplicationContext : 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$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
2017-05-06 22:44:18.871 INFO 41648 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service Tomcat
2017-05-06 22:44:18.902 INFO 41648 --- [ restartedMain] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-05-06 22:44:18.907 ERROR 41648 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
這是因?yàn)閟pring boot默認(rèn)會(huì)加載org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration類,DataSourceAutoConfiguration類使用了@Configuration注解向spring注入了dataSource bean。因?yàn)楣こ讨袥]有關(guān)于dataSource相關(guān)的配置信息,當(dāng)spring創(chuàng)建dataSource bean因缺少相關(guān)的信息就會(huì)報(bào)錯(cuò)满葛。
因?yàn)槲覂H僅只是使用spring boot來寫一些很簡(jiǎn)單的例子來學(xué)習(xí)它蜂林,在Application類上增加@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
阻止spring boot自動(dòng)注入dataSource bean