Reset Embedded H2 database periodically

前端 未结 6 1194
青春惊慌失措
青春惊慌失措 2021-02-01 13:17

I\'m setting up a new version of my application in a demo server and would love to find a way of resetting the database daily. I guess I can always have a cron job executing dro

6条回答
  •  别跟我提以往
    2021-02-01 13:41

    If you are using spring boot see this stackoverflow question

    1. Setup your data source. I don't have any special close on exit.

      datasource: driverClassName: org.h2.Driver url: "jdbc:h2:mem:psptrx"

    2. Spring boot @DirtiesContext annotation

      @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)

    3. Use @Before to initialise on each test case.

    The @DirtiesContext will cause the h2 context to be dropped between each test.

提交回复
热议问题