【问题标题】:APPLICATION FAILED TO START in Spring Boot应用程序无法在 Spring Boot 中启动
【发布时间】:2021-11-25 20:55:54
【问题描述】:

我有默认的弹簧应用程序并抛出此警告并停止工作 没有控制器和服务它只是一个演示应用程序



WARN 9256 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
11:00 ERROR 9256 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

【问题讨论】:

  • 你能分享你的属性文件吗?
  • 您从哪里获得演示应用程序,自述文件是否指定了有关创建数据库的任何内容?看起来您的 application.properties 文件没有详细说明数据源,但您的 spring 项目配置为期望一个。
  • 属性文件只有 server.local=8080 和我在 spring initializr 中创建的演示应用
  • 我的 pom 文件有这个依赖项:spring-boot-starter-data-jpa、spring-boot-starter-web、spring-boot-devtools、spring-boot-starter-test
  • 谢谢它只是为了检查 spring 是否在我的工作计算机中工作,我只是删除 spring 数据依赖项并且工作,但是当我必须使用 spring 数据依赖项时,我会检查你告诉我的内容跨度>

标签: java spring spring-boot hibernate spring-mvc


【解决方案1】:

确保您的 application.properties 文件中的数据是否正确填写。

spring.datasource.url=jdbc:postgresql://localhost:5432/your_database_name
spring.datasource.username=username
spring.datasource.password=password
spring.jpa.database=postgresql
spring.jpa.hibernate.ddl-auto=update 

【讨论】:

    【解决方案2】:

    如果你有spring数据作为依赖,你需要在你的application.properties文件中指定一个数据源url来连接数据库。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    • 谢谢,这只是为了检查 spring 是否在我的工作计算机上工作,我只是删除了依赖项并工作,但是当我必须使用 spring 数据依赖项时,我会按照你告诉我的去做
    猜你喜欢
    • 2015-05-10
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 2016-12-28
    相关资源
    最近更新 更多