【问题标题】:Spring boot Startup Error春季启动启动错误
【发布时间】:2018-05-03 05:45:26
【问题描述】:

当我尝试运行 spring boot 应用程序时,出现以下错误

starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-05-03 10:50:09.457 ERROR 4909 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

*************************** APPLICATION FAILED TO START
***************************

Description:

Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-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).

【问题讨论】:

  • 你的 pom.xml 中是否包含spring-boot-starter-data-jpa?它将假定您将处理数据存储。
  • 请发布您的 pom 或 gradle 文件的 sn-p 以及您的 application.properties
  • 您是否在 application.properties 或 yml 文件中包含 spring.datasource.url

标签: spring-boot


【解决方案1】:

如果您想使用非嵌入式数据源,上述答案是正确的。如果您想使用嵌入式数据源,您只需将以下依赖项添加到您的 pom.xml

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
</dependency>

如果您想在测试中使用嵌入式数据源,请将范围更改为 test 而不是 runtime

【讨论】:

    【解决方案2】:

    如果您想自动配置数据源,请将配置详细信息放在application.properties 文件中。像这样的东西(MySQL的配置)

    spring.datasource.url=jdbc:mysql://localhost/test
    spring.datasource.username=dbuser
    spring.datasource.password=dbpass
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    

    【讨论】:

      猜你喜欢
      • 2017-10-10
      • 2017-11-05
      • 2014-08-12
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      相关资源
      最近更新 更多