spring boot startup error Error starting ApplicationContext (failed to configure the data source)

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

Failed to configure data sources: not specified "url" attribute can not configure the embedded data source.

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-03 09:47:45.300 ERROR 23160 --- [           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).

the reason:

spring boot is loaded by default org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration class, DataSourceAutoConfiguration class uses the annotation @Configuration injected dataSource bean to spring. Because the project is not related to the dataSource configuration information, create dataSource bean when spring due to a lack of relevant information will be given.

Two solutions 

1. Application class added to the

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

2. Configuration Data Source:

For example in the application configuration file:

= class-name-spring.datasource.driver com.mysql.jdbc.Driver
spring.datasource.url = jdbc: MySQL: // ip: port number / name of the database useSSL = false & useUnicode = true & characterEncoding = utf8 & serverTimezone = GMT% 2B8?

Guess you like

Origin www.cnblogs.com/zouwangblog/p/10979134.html