Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 - Database is already closed

Tags:

spring-boot

h2

I'm trying to use the H2 database in a Spring Boot project. When I run a project, a database error pops up:

Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE"; to the db URL) [90121-199]

When I add: ";DB_CLOSE_ON_EXIT=FALSE"; this url also closes but without warning. What could be the problem?

application.properties:

spring.h2.console.enabled=true
spring.h2.console.path=/h2

spring.datasource.url=jdbc:h2:file:~/database
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver

Maven pom:

 <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
like image 508
xampo Avatar asked Apr 16 '26 03:04

xampo


2 Answers

If you still need it, for me the that problem was resolved adding the reference to module web of Spring in pom.xml

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
like image 169
Marco Muñoz Avatar answered Apr 19 '26 00:04

Marco Muñoz


add the below line in application.property file

spring.jpa.defer-datasource-initialization=true

like image 36
mahadevaprasad A M Avatar answered Apr 19 '26 01:04

mahadevaprasad A M