H2 Web Console to In Memory Database – Spring Boot

本文介绍如何在SpringBoot项目中集成H2数据库Web控制台,通过配置H2的WebServlet并映射到指定路径,实现对内存数据库的在线管理与操作。

To get an H2 Database Web Console accessing an in-memory database running on Spring Boot:

  1. Register H2’s WebServlet (with UrlMapping /console/*) to your Spring project in a Configuration annotated class. Restart your Application.
  2. Open a web page to http://localhost:8080/console/
  3. Be sure you’re accessing the correct database JDBC URL (default would be jdbc:h2:mem:testdb)

(Credit: Spring Framework Guru)

import org.h2.server.web.WebServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class H2ConsoleWebConfiguration {

    @Bean
    ServletRegistrationBean h2servletRegistration() {
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(new WebServlet());
        registrationBean.addUrlMappings("/console/*");
        return registrationBean;
    }
}

转载于:https://my.oschina.net/boltwu/blog/776346

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值