1兜喻、問題現(xiàn)象
通過spring官網(wǎng)生成Spring boot項(xiàng)目時(shí)如果選擇了數(shù)據(jù)庫梦染,或者依賴的maven modoule有依賴數(shù)據(jù)庫驅(qū)動(dòng)、druid等朴皆,則在啟動(dòng)會(huì)報(bào)類似異常:
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).
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:246) ~[spring-boot-autoconfigure-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineUsername(DataSourceProperties.java:328) ~[spring-boot-autoconfigure-1.5.7.RELEASE.jar:1.5.7.RELEASE]
at com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceWrapper.afterPropertiesSet(DruidDataSourceWrapper.java:44) ~[druid-spring-boot-starter-1.1.3.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
2帕识、問題分析
spring boot所依賴的maven模塊中含有數(shù)據(jù)庫相關(guān)的組件,這些組件在初始化時(shí)會(huì)自動(dòng)注入數(shù)據(jù)源遂铡,然后在配置文件中找不到數(shù)據(jù)源配置信息肮疗,因此拋出異常。
3扒接、解決方案
如果不需要數(shù)據(jù)庫支持伪货,將pom文件中的數(shù)據(jù)庫相關(guān)的依賴刪除,即可正常啟動(dòng)钾怔。
如果依賴的maven公共模塊依賴了數(shù)據(jù)庫驅(qū)動(dòng)碱呼,但是本工程沒有用到數(shù)據(jù)庫相關(guān)的功能,則可以在本工程的@SpringBootApplication中排除數(shù)據(jù)庫相關(guān)的注入
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
- 如果本工程用到了數(shù)據(jù)庫宗侦,則提供數(shù)據(jù)源的相關(guān)配置愚臀。