0

I am stuck in this, trying to change my h2 db from in memory to file based. But everytime on restart, it automatically connects to in memory.

Here is my application.properties

server.port=8010
spring.datasource.url=jdbc:h2:file:~/transactionsdb;AUTO_SERVER=TRUE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=user
spring.datasource.password=password
#spring.sql.init.continue-on-error=true
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.show-sql=true
spring.h2.console.enabled=true
#spring.jpa.defer-datasource-initialization=true
spring.jpa.hibernate.ddl-auto=none

Please help me to progress. Thanks in advance

1 Answer 1

1

This is my application.yml file and on restart H2 database is connecting to the file database. I have created test1.mv.db file in /Users/rohit/ directory.

spring:
  h2:
    console:
      enabled: true
  datasource:
    url: jdbc:h2:file:/Users/rohit/test1
    username: sa
    password:
  data:
    jpa:
      repositories:
        bootstrap-mode: default

In application start-up logs also I can see the same information

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

HI @Rohit, this test1.mv.db file is created by you or is it automatically created?
It is automatically created.
@ManojMajumdar - If my answer helps request you to please accept it so that it helps others as well.
The problem was with my datasource configuration, I had another embedded datasource configuration in my @configuration file, which ignored the configuration of my properties file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.