View content of embedded H2 database started by Spring

前端 未结 7 1001
忘掉有多难
忘掉有多难 2020-12-04 09:53

I would like to view in a web browser the content of the H2 database started by Spring thanks to the following configuration:



        
7条回答
  •  有刺的猬
    2020-12-04 10:20

    The database URL jdbc:h2:mem:dataSource means you are using an in-memory database. Now if you start a second Java process and connect to this database, you will end up having two in-memory databases (one for each process).

    If you want to connect to the existing database, you have multiple options:

    • Connect to the database from within the same process. Don't start a second process.

    • Use a persisted database, with a hardcoded absolute path, for example: `jdbc:h2:/data/db/dataSource'.

    • More complicated / not recommended: If you start a second process, you could theoretically connect to an in-memory database using the server mode. But that means you need to start the server where you ran the test.

提交回复
热议问题