Spring boot 报错:Cannot determine embedded database driver class for database type NONE




Cannot determine embedded database driver class for database type NONE

谷歌翻译:

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


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


 
 
  1. . ____ _ __ _ _
  2. /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  3. ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  4. \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. ' |____| .__|_| |_|_| |_\__, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v1.5.6.RELEASE)
  8. 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)
  9. 2017-09-11 17:13:53.944 INFO 15808 --- [ main] com.spring.web.DemoApplication : No active profile set, falling back to default profiles: default
  10. 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
  11. 2017-09-11 17:13:55.869 INFO 15808 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
  12. 2017-09-11 17:13:55.881 INFO 15808 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
  13. 2017-09-11 17:13:55.882 INFO 15808 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16
  14. 2017-09-11 17:13:56.065 INFO 15808 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
  15. 2017-09-11 17:13:56.065 INFO 15808 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2058 ms
  16. 2017-09-11 17:13:56.197 INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
  17. 2017-09-11 17:13:56.200 INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
  18. 2017-09-11 17:13:56.201 INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  19. 2017-09-11 17:13:56.201 INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  20. 2017-09-11 17:13:56.201 INFO 15808 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
  21. 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).
  22. 2017-09-11 17:13:56.238 INFO 15808 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
  23. 2017-09-11 17:13:56.250 INFO 15808 --- [ main] utoConfigurationReportLoggingInitializer :
  24. Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  25. 2017-09-11 17:13:56.254 ERROR 15808 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
  26. ***************************
  27. APPLICATION FAILED TO START
  28. ***************************
  29. Description:
  30. Cannot determine embedded database driver class for database type NONE
  31. Action:
  32. 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加上数据源的配置:


 
 
  1. spring.datasource.url = jdbc:mysql://xxx.xx.xxx.xxx:3306/qqzhanghao?useUnicode=true&characterEncoding=UTF-8&useSSL=false
  2. spring.datasource.username = root
  3. spring.datasource.password = admin123456
  4. spring.datasource.driverClassName = com.mysql.jdbc.Driver
  5. spring.datasource.max-active=20
  6. spring.datasource.max-idle=8
  7. spring.datasource.min-idle=8
  8. spring.datasource.initial-size=10

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


 
 
  1. <dependency>
  2. <groupId>com.h2database</groupId>
  3. <artifactId>h2</artifactId>
  4. <version>1.3.156</version>
  5. </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





        </div>
            </div>
        </article>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值