spring jpa 存储库在哪里存储数据?

where does spring jpa repository store data?

是否将其存储在缓存中?我有一个应用程序,application.properties 中没有提到数据库的详细信息。我可以存储数据并通过 Postman 进行查询。

Spring Boot 使用自动配置根据 class 路径上存在的依赖项配置持久性。例如,如果您在 pom.xml 中提供对 spring-boot-starter-data-jpa 的依赖项而没有其他配置,则 JPA/Hibernate 默认使用内存中的 H2 数据库。您可以通过将以下内容添加到 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

默认情况下,内存中 H2 数据库的内容存储在易失性内存中,因此当您的应用程序终止时将会丢失。您可以通过将此添加到 application.properties:

来将数据存储到本地文件
spring.datasource.url=jdbc:h2:file:/path/to/my/data

要在控制台中查看 H2 数据库的内容,请将以下内容添加到 application.properties 并转到 http://localhost:8080/h2-console :

spring.h2.console.enabled=true