【问题标题】:Spring h2-console not openingSpring h2-console 未打开
【发布时间】:2021-06-26 17:05:02
【问题描述】:

我试图在我的 Spring Boot 应用程序上打开我的 h2-console,但它给了我“Whitelabel Error Page”。 我已经配置了我的 application.properties 文件

spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:testdb

为 h2 db 添加了依赖项:

 <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
            <dependency>
                <groupId>com.h2database</groupId>
                <artifactId>h2</artifactId>
                <version>1.4.200</version>
                <scope>test</scope>
            </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

尝试重建项目并检查 https 自动重定向

【问题讨论】:

  • 也许尝试将此spring.h2.console.path=/h2-console 添加到您的application.properties 并通过http://localhost:port/h2-console 访问它我还注意到您依赖于test scope ???也许将其更改为runtime
  • 删除了测试范围,我将其添加到属性仍然无法正常工作...之前尝试使用完整的 url,它看起来不是因为谷歌浏览器上的 https 重定向问题
  • 还有一个问题,为什么h2 有两个依赖项?我只会保留&lt;dependency&gt; &lt;groupId&gt;com.h2database&lt;/groupId&gt; &lt;artifactId&gt;h2&lt;/artifactId&gt; &lt;scope&gt;runtime&lt;/scope&gt; &lt;/dependency&gt;
  • runtime 解决了问题.. 对不起,如果这是一个愚蠢的问题,但我可以标记评论,就像我可以标记我解决了问题的答案...如果不写所有这些回答亚里士多德,这样我就可以标记它并给你投票:)
  • 我也会写一个答案。所以其他人可以找到它:) 很高兴我帮助了

标签: java h2


【解决方案1】:

将您的 H2 依赖项从测试更改为运行时

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>

【讨论】:

    【解决方案2】:

    通过添加一个带有&lt;scope&gt;test&lt;/scope&gt; 的依赖项,它表示该依赖项 应用程序正常使用不需要,仅在测试编译和执行阶段可用

    所以把它改成runtime,因为这个范围表明依赖不是编译所必需的,而是执行所必需的。 Maven 在运行时和测试类路径中包含具有此范围的依赖项,但不包括编译类路径。

    这将解决您的问题:

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
    

    您可以阅读有关范围的更多信息here

    【讨论】:

      猜你喜欢
      • 2017-01-16
      • 2019-03-20
      • 2018-07-11
      • 2017-10-03
      • 2022-12-05
      • 2019-04-23
      • 1970-01-01
      • 2017-12-24
      • 2015-06-09
      相关资源
      最近更新 更多