关于Springboot:Cannot determine embedded database driver class for database type NONE解决办法

Cannot determine embedded database driver class for database type NONE

谷歌翻译:

无法确定数据库类型无嵌入式数据库驱动程序类


启动Spring boot 简单的demo项目时 报错:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.6.RELEASE)

2017-09-11 17:13:53.942  INFO 15808 --- [           main] com.spring.web.DemoApplication           : Starting DemoApplication on PC2014101864 with PID 15808 (E:\workspacedubbo\boot\boot-web\target\classes started by Administrator in E:\workspacedubbo\boot\boot-web)
2017-09-11 17:13:53.944  INFO 15808 --- [           main] com.spring.web.DemoApplication           : No active profile set, falling back to default profiles: default
2017-09-11 17:13:54.010  INFO 15808 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@11e21d0e: startup date [Mon Sep 11 17:13:54 CST 2017]; root of context hierarchy
2017-09-11 17:13:55.869  INFO 15808 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-09-11 17:13:55.881  INFO 15808 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-09-11 17:13:55.882  INFO 15808 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.16
2017-09-11 17:13:56.065  INFO 15808 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-09-11 17:13:56.065  INFO 15808 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2058 ms
2017-09-11 17:13:56.197  INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-09-11 17:13:56.200  INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-09-11 17:13:56.201  INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-09-11 17:13:56.201  INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-11 17:13:56.201  INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-09-11 17:13:56.236  WARN 15808 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': 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$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-09-11 17:13:56.238  INFO 15808 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2017-09-11 17:13:56.250  INFO 15808 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-09-11 17:13:56.254 ERROR 15808 --- [           main] 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).

错误原因:

springboot默认是需要datasource的,如果你没有配置datasource就会报上面的错误

具体原因还不知道,等以后研究明白再更新。


解决办法:

1.在src/main/resources文件夹下添加aplication.properties加上数据源的配置:

spring.datasource.url = jdbc:mysql://xxx.xx.xxx.xxx:3306/qqzhanghao?useUnicode=true&characterEncoding=UTF-8&useSSL=false
spring.datasource.username = root
spring.datasource.password = admin123456
spring.datasource.driverClassName = com.mysql.jdbc.Driver

spring.datasource.max-active=20    
spring.datasource.max-idle=8
spring.datasource.min-idle=8
spring.datasource.initial-size=10

2.去过现在没有数据源。找到一个国外问类似问题的,有一个人给出的答案是在pom.xml里加上h2database的依赖

<dependency> <groupId>com.h2databasegroupId> <artifactId>h2artifactId> <version>1.3.156version> dependency>
个人认为: h2database是java的嵌入式数据库,正好满足了spring boot 默认需要datasource的需求。(ps:有兴趣可以学习下h2)

下面有人问你确定你要在我们讨论GAE/Datastore的时候乱入H2 database?一个人跟进说他成功了,又有一个人说他也成功了。于是我试了一下,搞定了!

后面有人分析说因为Spring Boot会自动载入几种数据库,所以需要Datasource等等,另一个人说只要在spring-boot-starter-data-jpa依赖中去掉hibernate-entitymanager,但我没成功,看评论也有怀疑他写错了的。还有人想取消DataSourceAutoConfiguration,有空再研究下。

reference:http://stackoverflow.com/questions/24074749/spring-boot-cannot-determine-embedded-database-driver-class-for-database-type





你可能感兴趣的:(spring,boot)