初建一个简单的spring boot 项目,启动后会报错。


  1. 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$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
  2. 2019-01-27 14:36:35.101 INFO 5484 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'
  3. 2019-01-27 14:36:35.104 INFO 5484 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
  4. 2019-01-27 14:36:35.116 INFO 5484 --- [ main] ConditionEvaluationReportLoggingListener :
  5. Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
  6. 2019-01-27 14:36:35.123 ERROR 5484 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
  7. ***************************
  8. APPLICATION FAILED TO START
  9. ***************************
  10. Description:
  11. Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
  12. Reason: Failed to determine a suitable driver class
  13. Action:
  14. Consider the following:
  15. If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
  16. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
  17. Process finished with exit code 1

报错信息说明的很详细:就是在项目启动的时候在 resource目录下没有加载到配置信息;如果项目只是想简单的启动运行,不进行数据库操作可以在 启动类上做如下处理便可解决。

  • @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
    
  • 如果对数据库操作有要求的话在application文件中加入配置
  • 
    
    1. spring:
    2. datasource:
    3. url: jdbc:mysql://localhost:3306/数据库名称?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    4. username: 数据库用户名
    5. password: 数据库密码
    6. # 如果在pom 文件中没有依赖数据库连接这个会报红,加入 ‘mysql-connector-java’ 即可,如果还是报红的话,给出 <version>8.0.13</version> 具体版本号即可,如果还是不行,可能是其他引入的spring相关 jar 包的 pom 坐标依赖有冲突,删除即可。但是在启动后后台打印日志会报红
    7. #《Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is #`com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual #loading of the driver class is generally unnecessary.》
    8. # 把驱动名称:com.mysql.jdbc.Driver 换成 com.mysql.cj.jdbc.Driver 即可
    9. driver-class-name: com.mysql.jdbc.Driver
    10. spring:
    11. datasource:
    12. url: jdbc:mysql://localhost:3306/数据库名称?useUnicode=true&characterEncoding=UTF-8&useSSL=false
    13. username: 数据库用户名
    14. password: 数据库密码
    15. driver-class-name: com.mysql.cj.jdbc.Driver
  • 在spring xml配置文件中引用了数据库地址 所以需要对:等进行转义处理.但是在application.properties/或者application.yml文件并不需要转义,错误和正确方法写在下面了.

  1. //错误示例
  2. spring.datasource.url = jdbc:mysql\://192.168.0.20\:1504/f_me?setUnicode=true&characterEncoding=utf8

  1. //正确示例
  2. spring.datasource.url = jdbc:mysql://192.168.0.20:1504/f_me?setUnicode=true&characterEncoding=utf8
  • yml或者properties文件没有被扫描到,需要在pom文件中<build></build>添加如下.来保证文件都能正常被扫描到并且加载成功.

  1. <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
  2. <resources>
  3. <resource>
  4. <directory>src/main/java</directory>
  5. <includes>
  6. <include>**/*.yml</include>
  7. <include>**/*.properties</include>
  8. <include>**/*.xml</include>
  9. </includes>
  10. <filtering>false</filtering>
  11. </resource>
  12. <resource>
  13. <directory>src/main/resources</directory>
  14. <includes>
  15. <include>**/*.yml</include>
  16. <include>**/*.properties</include>
  17. <include>**/*.xml</include>
  18. </includes>
  19. <filtering>false</filtering>
  20. </resource>
  21. </resources>

如果是:

com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

加上 &serverTimezone=UTC 即可 。如:


  1. com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
  2. # 解决方案
  3. druid.jdbcUrl=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

链接:https://www.jianshu.com/p/836d455663da

spring boot项目启动报DataSource错误的更多相关文章

  1. 创建spring boot项目启动报错遇到的问题

    1.Spring boot,Mybatis 启动报错 Failed to auto-configure a DataSource *************************** APPLICA ...

  2. spring boot项目启动报(No session repository could be auto-configured, check your configuration (session store type is 'null'))

    找到项目的application配置文件,增加 spring.session.store-type=none,重新启动问题解决 注:因为项目未使用redis管理session,可以如上设置,如果想使用 ...

  3. spring boot项目启动报错

    在eclipse中运行没有任何问题,项目挪到idea之后就报错 Unable to start EmbeddedWebApplicationContext due to miss EmbeddedSe ...

  4. 让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean

    让Spring Boot项目启动时可以根据自定义配置决定初始化哪些Bean 问题描述 实现思路 思路一 [不符合要求] 思路二[满足要求] 思路三[未试验] 问题描述 目前我工作环境下,后端主要的框架 ...

  5. spring boot 项目启动无任何反应

    遇到的问题 spring boot项目启动后无任何报错,ps有进程,nohub无日志 定位 更换jar包,问题依然存在,将jar包放到其他服务器,运行正常,排除打包问题 同服务器其他系统运行正常,但停 ...

  6. 第一个Spring Boot程序启动报错了

    创建完成第一个Spring Boot项目后,准备运行,尝一下胜利的果实. 启动日志如下 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ...

  7. 【问题篇四】启动报DataSource错误

    初建一个简单的spring boot 项目,启动后会报错:就是在项目启动的时候在 resource目录下没有加载到配置信息:如果项目只是想简单的启动运行,不进行数据库操作可以在 启动类上做如下处理便可 ...

  8. Spring boot&Mybatis 启动报错 Failed to auto-configure a DataSource

    *************************** APPLICATION FAILED TO START *************************** Description: Fai ...

  9. boot 项目启动报Cannot datermine embedded database driver class for database type NONE

    部署boot项目时报Cannot datermine embedded database driver class for database type NONE数据库链接什么的也都没有问题,经过百度 ...

随机推荐

  1. 阿里云CentOs7上安装GitLab

    一.安装 基本上可以根据官网的教程来安装:https://www.gitlab.com.cn/installation/#centos-7 只不过我们暂时没有邮件服务器,所以postfix没有安装. ...

  2. node环境下安装vue-cli

    一. node安装 1)如果不确定自己是否安装了node,可以在命令行工具内执行: node -v  (检查一下 版本): 2)如果 执行结果显示: xx 不是内部命令,说明你还没有安装node , ...

  3. 17.splash_case03

    # python执行lua脚本 import requests from urllib.parse import quote lua = ''' function main(splash) retur ...

  4. Post Office IOI 2000 /// 区间DP oj24077

    题目大意: 给定n个村庄的坐标,两个村庄之间的距离是其坐标之差的绝对值 最多能选m个村庄设立邮局,求设立邮局的地点使得各村庄与邮局距离总和最小 一, 所有的村庄看做在一条直线上 考虑三个因素:i 当前 ...

  5. 01.MyBatis快速入门

    1.下载jar包 Mybatis包+数据库驱动包 https://github.com/mybatis/mybatis-3/releases 2.新建Java工程并导入jar包 3.创建数据库与表 C ...

  6. Java虚拟机性能管理神器 - VisualVM(2) 入门【转】

    Java虚拟机性能管理神器 - VisualVM(2) 入门[转] 标签: java插件jvm监控工具入门 2015-03-11 16:54 955人阅读 评论(0) 收藏 举报  分类: Visua ...

  7. git归纳总结

    1,git 是分布式版本控制:单个电脑就是一个完整的版本库,只需向中央服务器(远程服务器)提交修改的部分.在没有网络情况下也能正常想本机服务器提交代码管理版本,有网时再推送到远程服务器.   svn是 ...

  8. [JZOJ4759] 【雅礼联考GDOI2017模拟9.4】石子游戏

    题目 描述 题目大意 在一棵树上,每个节点都有些石子. 每次将mmm颗石子往上移,移到根节点就不能移了. 双方轮流操作,问先手声还是后手胜. 有三种操作: 1. 询问以某个节点为根的答案. 2. 改变 ...

  9. 完全卸载之前8.0的Mysql,安装5.5mysql

    完全卸载: https://blog.csdn.net/sxingming/article/details/52601250 安装mysql5.5: https://blog.csdn.net/fly ...

  10. l洛谷 NOIP提高组模拟赛 Day2

    传送门 ## T1 区间修改+单点查询.差分树状数组. #include<iostream> #include<cstdio> #include<cstring> ...