H2控制台未显示

时间:2019-07-29 13:17:18

标签: java spring spring-boot h2

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

时,出现 whitlabel错误页面

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

    <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

enter image description here

1 个答案:

答案 0 :(得分:5)

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 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