我试图在本地主机上运行spring boot应用程序,通常我应该第一次出现Whitelabel错误页面,但是在运行它时却遇到了这个错误。
***************************
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
答案 0 :(得分:2)
如日志中所示,您尝试在不提供有关数据库信息的情况下运行该应用程序。
Spring和Spring-boot并非完全基于魔术。
url
。如果要使用内存数据库运行应用程序,请对类路径具有此依赖性:
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
确保此依赖项中没有<scope>test</scope>
。而且,在运行时,spring-boot
将自动连接到您的hsqldb
数据库。
spring-boot
将无法猜测什么是连接信息,例如url
或数据库名称。并且您必须在application.properties
文件中提供以下属性:spring.datasource.url=jdbc:postgresql://<database_host>:<port>/<database_name>
spring.datasource.username=myUser
spring.datasource.password=secret
spring.datasource.type= (Not necessary)
如果您不提供该信息,那就像在不提供地址的情况下发邮件...您找不到所需的人。
希望有帮助!
答案 1 :(得分:0)
如日志所示,您必须查看数据源配置,并确保一切都很好。