报错信息:配置数据源失败:未指定'url'属性,且无法配置嵌入的数据源。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-06-21 21:10:25.354 ERROR 16588 --- [ restartedMain] 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).
Disconnected from the target VM, address: '127.0.0.1:60702', transport: 'socket'
Process finished with exit code 0
经过我不断排查,知道了报错原因:
有2种情况
一种为resources中的yml或者prooerties的配置信息错误
yml后缀的配置文件要注意缩进(yml文件的 ":" 前面必须有用空格! ),或者看看是不是哪个地方多了一个英文字母,或少写了一个英文字母,导致的数据源无法被springboot扫描到
另外一个就是pon.xml中没有引入相关的依赖
<!-- jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 数据库驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
当我们在配置这两个文件之后,重新启动项目就没有问题了