Tag Archives: Failed to determine a suitable driver class

SpringBoot Frame: Failed to determine a suitable driver class [How to Solve]

. ____ _ __ _ _
/\\/___’_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
‘ |____| .__|_| |_|_| |_\__, |////
=========|_|==============|___/=/_/_/_/
:: 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).

Resolution:

Build a simple introductory test based on springboot and springcloud framework. The error report is as follows:

reason:

This is because the database component is added, so autoconfig will read the data source configuration, but the newly created project has not been configured. The data source/url address is wrong, so an exception will occur.

Solution:

1. Add exclude = {datasourceautoconfiguration. Class} in @ enableautoconfiguration or @ springbootapplication of startup class to exclude autoconfig of this class. After startup, it can run normally.

1 @MapperScan("com.wsc.core.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 }

II. The URL address in application.yml cannot be recognized, and the format is wrong.

Strict writing requirements for yaml format files (equal order flush, top grid input)

 1 server:
 2   port: 8001
 3 mybatis:
 4   config-location: classpath:mybatis/mybatis.cfg.xml #mybatis Configuration file path
 5 type-aliases-package: com.wsc.core.pojo # package where the entity alias class is located
 6 mapper-locations: mybatis/mapper/*.xml # mapper mapping file
 7 spring:
 8 application:
 9 name: microserver-product # This is very important, this is generally based on this name in the future service to service calls between each other
10 datasource:
11 type: com.alibaba.druid.pool.
12 driver-class-name: com.mysql.cj.jdbc.
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 # Minimum number of maintained connections for the database connection pool
18 initial-size: 5 # Initialize the number of connections
19 max-total: 5 # Maximum number of connections
20 max-wait-millis: 150 # Maximum timeout to wait for a connection to be fetched

YML file