我正在尝试学习 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-STARTER-WEB 依赖项
就我而言,我忘记在 pom.xml 中添加 spring-boot-starter-web 作为依赖项。
在pom.xml文件中添加以下代码后问题解决:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>