【问题标题】:H2 console does not show upH2 控制台不显示
【发布时间】:2019-07-29 13:17:18
【问题描述】:

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

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

<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

【问题讨论】:

    标签: java spring spring-boot h2


    【解决方案1】:

    应用程序属性中添加这个

    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 Initialzr 的 Spring Boot 2.x:

    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

    【讨论】:

      猜你喜欢
      • 2019-03-20
      • 2018-04-11
      • 1970-01-01
      • 2023-02-08
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      • 2017-05-19
      相关资源
      最近更新 更多