Spring Boot使用问题集合

  1. Cannot determine embedded database driver class for database type NONE
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

原因:如果pom选中引入了spring-boot-starter-data-jpa或数据库相关的,Spring Boot启动默认会加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当Spring创建dataSource bean因缺少相关的信息就会报错。

解决办法:pom中去掉数据库相关的引用,或者在@SpringBootApplication中排除其注入
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})

你可能感兴趣的:(Spring,Boot)