H2 控制台不显示

H2 console does not show up

我已经阅读了几乎所有关于 H2 控制台的问题,但没有找到解决方案。当我点击 URL http://localhost:8080/h2-console.

时,我收到 Whitelabel Error Page

我在我的项目中添加了以下依赖项:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>>
    </dependency>
</dependencies>

application.properties

spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

application-properties

中添加
spring.h2.console.path=/h2-console

H2 的属性

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.path=/h2-console

DB_CLOSE_DELAY = -1 是防止连接丢失


更新

对于 Spring 引导 2.x 直接从 Spring Initialzr:

devtools 默认为 http://127.0.0.1:8080/h2-console/

POM:spring-boot-starter,h2,spring-boot-starter-web,spring-boot-devtools

没有 devtools - 您需要在属性中设置它:

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

POM:spring-boot-starter,h2,spring-boot-starter-web