Failed to determine a suitable driver class(基于SpringBoot框架)

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

2019-08-27 11:31:57.774 ERROR 15364 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

解析:

            搭建基于SpringBoot ,springCloud 框架简单入门 的测试。报错如上:

原因:

            这是因为添加了数据库组件,所以autoconfig会去读取数据源配置,而新建的项目还没有配置数据源/URL地址错误,所以会导致异常出现。 

解决方案:

           一。 在启动类的@EnableAutoConfiguration或@SpringBootApplication中添加exclude = {DataSourceAutoConfiguration.class},排除此类的autoconfig。启动以后就可以正常运行。   

1 @MapperScan("com.wsc.core.mapper")//映射mapper地址
2 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
  //启动类 SpringBoot
3 public class Start { 4 public static void main(String[] args) { 5 SpringApplication.run(Start.class,args); 6 } 7 }

    二。application.yml中的URL地址识别不出来,格式写错。

   yaml格式文件的写入 要求严格 (等阶平齐,顶格输入)

 1 server:
 2   port: 8001
 3 mybatis:
 4   config-location: classpath:mybatis/mybatis.cfg.xml #mybatis 配置文件路径
 5   type-aliases-package: com.wsc.core.pojo # entity别名类所在包
 6   mapper-locations: mybatis/mapper/*.xml    # mapper映射文件
 7 spring:
 8   application:
 9     name: microserver-product #这个很重要,这在以后的服务与服务之间相互调用一般都是根据这个name
10   datasource:
11     type: com.alibaba.druid.pool.DruidDataSource
12     driver-class-name: com.mysql.cj.jdbc.Driver
13     url: jdbc:mysql://127.0.0.1:3306/springcloud_db01?serverTimezone=GMT%2B8
14     password: wsc
15     username: root
16     dbcp2:
17       min-idle: 5                         # 数据库连接池的最小维持连接数
18       initial-size: 5                     # 初始化连接数
19       max-total: 5                        # 最大连接数
20       max-wait-millis: 150                # 等待连接获取的最大超时时间
yml文件

  

原文地址:https://www.cnblogs.com/wangshichang/p/11418818.html