1. 异常现象
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 (the profiles stg are currently active).
2023-08-17 14:32:52.532 [TID:] [Curator-Framework-0] INFO CuratorFrameworkImpl.backgroundOperationsLoop():955 - backgroundOperationsLoop exiting
2023-08-17 14:32:52.546 [TID:] [DubboShutdownHook] INFO ZooKeeper.close():693 - Session: 0x10115d8a9bb1776 closed
2023-08-17 14:32:52.548 [TID:] [main-EventThread] INFO ClientCnxn.run():522 - EventThread shut down for session: 0x10115d8a9bb1776
2. 异常原因
这个错误信息表明在你的 Spring Boot 应用程序中出现了数据库连接配置的问题。
具体来说,错误信息中提到了:
- ‘url’ 属性未指定,并且没有嵌入式数据源可以配置。
- 无法确定合适的驱动程序类。
这通常是因为 Spring Boot 需要数据库连接的配置,而你没有在配置文件中提供相应的配置。
3. 解决方案
-
检查数据库配置: 确保在你的项目配置文件中(通常是 application.properties 或 application.yml)正确配置了数据库连接信息。你需要至少指定 spring.datasource.url、spring.datasource.username 和 spring.datasource.password 等属性。如果使用的是 Apollo 配置,记得仔细检查核对 namespaces 配置有无缺漏,多半可能就是这个原因。
-
检查驱动程序依赖: 确保你的项目的依赖中包含了正确的数据库驱动程序依赖。不同的数据库使用不同的驱动程序,你需要根据你使用的数据库来选择合适的驱动程序依赖。
-
检查激活的配置文件: 错误信息中提到了当前激活的配置文件是 “stg”。确保在 “stg” 对应环境配置文件中也有正确的数据库连接配置。
-
添加嵌入式数据库: 如果你想使用嵌入式数据库(如 H2、HSQL 或 Derby),请确保将它们添加到项目的依赖中。Spring Boot 在默认情况下支持嵌入式数据库,但你需要在配置文件中指定相关的连接信息。