错误如下
2017-12-25 09:54:11.645 WARN 1852 --- [ 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 (the profiles "dev" are currently active).
2017-12-25 09:54:11.660 INFO 1852 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
Disconnected from the target VM, address: '127.0.0.1:53388', transport: 'socket'
2017-12-25 09:54:11.676 INFO 1852 --- [ restartedMain] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-12-25 09:54:11.676 ERROR 1852 --- [ 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 (the profiles "dev" are currently active).
问题
这样的错误,一看就明白了,问题出现在了dataSource这儿
dataSource代表数据源,所以完全可以想象得到问题出现在哪里。我配置的是“yaml”,你们可以进行相应的修改
解决办法
以下仅仅作为参考
spring:
datasource:
url: jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=utf-8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
username: root
password:
minIdle: 5
maxActive: 100
initialSize: 10
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 50
removeAbandoned: true
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,log4j,logback
cachePrepStmts: true # 开启二级缓存
# 合并多个DruidDataSource的监控数据
useGlobalDataSourceStat: true

SpringBoot DataSource配置异常解析
本文解析了SpringBoot应用中因DataSource配置不当导致的启动失败问题,并提供了详细的解决方案及配置样例。
982

被折叠的 条评论
为什么被折叠?



