How to enable H2 Database Server Mode in Spring Boot

You can enable h2 web console to access your h2 in memory or in file database using a web interface in your browser.

therefor add in application.properties the lines:

spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

after that restart your spring boot application and check http://localhost:8080/h2-console with your browser.


You can start the H2 TCP server as a bean:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <!-- <scope>runtime</scope> -->
</dependency>
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    public Server h2Server() throws SQLException {
        return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092");
    }
}

Then connect to it from your IDE with the following params (password - empty):

url: jdbc:h2:tcp://localhost:9092/mem:testdb
user: sa

More info is here and here.