在本地主机上运行spring boot app时出错

时间:2020-01-11 15:53:47

标签: java spring spring-boot

我试图在本地主机上运行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

2 个答案:

答案 0 :(得分:2)

如日志中所示,您尝试在不提供有关数据库信息的情况下运行该应用程序。

Spring和Spring-boot并非完全基于魔术。

  • 如果您使用嵌入式数据源(如您提供的日志中所述),他们可以猜测一些数据库信息,例如url。如果要使用内存数据库运行应用程序,请对类路径具有此依赖性:

    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
    </dependency>

确保此依赖项中没有<scope>test</scope>。而且,在运行时,spring-boot将自动连接到您的hsqldb数据库。

  • 如果您正在运行应用程序,并且拥有面向生产的数据库(例如PostgreSQL),那么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)

如日志所示,您必须查看数据源配置,并确保一切都很好。