简体   繁体   中英

where does spring jpa repository store data?

Does it store it in cache? I have an application and nowhere in the application.properties are db details mentioned. I am able to store data and query it via Postman.

Spring Boot uses auto-configuration to configure persistence based on what dependencies are present on the class path. For example, If you provide a dependency to spring-boot-starter-data-jpa in pom.xml with no other config, JPA/Hibernate uses an in-memory H2 database by default. You can make this explicit by adding the following to application.properties :

spring.datasource.url=jdbc:h2:mem:testdb
spring.data.jpa.repositories.bootstrap-mode=default
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

By default, the contents of the in-memory H2 database are stored in volatile memory, so will be lost when your application terminates. You can store data to a local file by adding this to application.properties :

spring.datasource.url=jdbc:h2:file:/path/to/my/data

To view the contents of the H2 database in a console, add the following to application.properties and go to http://localhost:8080/h2-console :

spring.h2.console.enabled=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM