内存中 H2 数据库出错,对名称为“inMemoryDatabaseShutdownExecutor”的 bean 调用销毁方法失败

问题描述 投票:0回答:1

我正在尝试学习 Java Springboot 微服务,我创建了一个在内存 H2 数据库中使用的贷款微服务,但它给出了详细信息错误

2023-10-12T12:26:55.058+05:30  WARN 4228 --- [ionShutdownHook] o.s.b.f.support.DisposableBeanAdapter    : Invocation of destroy method failed on bean with name 'inMemoryDatabaseShutdownExecutor': org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL)

我已经尝试添加

DB_CLOSE_ON_EXIT=FALSE"
以及延迟选项,但它仍然不起作用

application.yml file
server:
  port: 8090
spring:
  datasource:
    url: jdbc:h2:mem:testdb;
    driverClassName: org.h2.Driver
    username: sa
    password: ''
  h2:
    console:
      enabled: true
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
    hibernate:
      ddl-auto: update
    show-sql: true
spring-boot h2
1个回答
0
投票

添加 Spring-BOOT-STARTER-WEB 依赖项

就我而言,我忘记在 pom.xml 中添加 spring-boot-starter-web 作为依赖项。

在pom.xml文件中添加以下代码后问题解决:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.