How to start H2 TCP server on Spring Boot application startup?

后端 未结 5 1072
青春惊慌失措
青春惊慌失措 2021-01-05 06:44

I\'m able to start the H2 TCP server (database in a file) when running app as Spring Boot app by adding following line into the SpringBootServletInitializer main method:

5条回答
  •  攒了一身酷
    2021-01-05 07:03

    Yup, straight from the documentation, you can use a bean reference:

    
    
    

    There's also a servlet listener option that auto-starts/stops it.

    That answers your question, but I think you should probably be using the embedded mode instead if it's deploying along with your Spring Boot application. This is MUCH faster and lighter on resources. You simply specify the correct URL and the database will start:

    jdbc:h2:/usr/share/myDbFolder
    

    (straight out of the cheat sheet).

提交回复
热议问题