【问题标题】:Database connection on H2 for Spring Petclinic projectSpring Petclinic 项目的 H2 数据库连接
【发布时间】:2021-05-14 00:47:50
【问题描述】:

我已经克隆并安装了spring petclinic project

它工作正常,但我不明白我是否以及如何访问 H2 db。

我看到在 application.properties 中没有用户名、密码和 dbname。

这是否意味着我无法从 /h2-console 访问它?因为它可能是嵌入的?

是否有其他设置(?服务器?)为了访问它?将是哪个配置?

【问题讨论】:

    标签: spring


    【解决方案1】:

    我使用了这个解决方案How to enable H2 Database Server Mode in Spring Boot

    基本上,它从 pom.xml 中的 h2 依赖项中删除运行时范围,并将 H2 作为 Spring 应用程序中的 Bean 启动。

    唯一额外的事情是我必须阅读 Spring 启动日志才能找到消息

    o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:27cca538-56b1-49d6-9b63-317e28c3e4a9'
    

    然后在控制台中使用用户“sa”和空密码的 jdbc URL。

    不是很懂,但是很好用……

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-12
      • 2020-09-03
      • 2018-12-21
      • 2012-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      相关资源
      最近更新 更多