描述
创建一个全新的springboot项目,第一次启动时报错,具体错误信息如下所示:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-14 17:58:10.322 ERROR 12292 --- [ 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).
Process finished with exit code 1
解决方案
- 方案一
在application.properties配置文件中添加数据库配置信息
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8
spring.datasource.username=cx
spring.datasource.password=123456
- 方案二
在启动类头部声明进行声明:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)