如何将H2控制台连接到嵌入式Spring H2 DB
好的,我正在开发简单的应用程序,它有Spring Ebedded H2数据库用于开发。 database.xml bean conf看起来像这样:
H2数据库正在初始化,我的应用程序正在运行,我正在创建实体,并且它们在Tomcat启动时存储在H2 db中(我知道它因为我使用并检索它们)。 但是,当我查看H2控制台时,我的实体表不存在。
我想H2控制台指向另一个H2数据库,而Spring Embedded H2 Db与那个H2控制台无关。
如何解决?
编辑:我通过在我的网络浏览器中输入http:// localhost:8082来访问H2控制台。
如果您的应用程序不是弹簧启动,则需要在web.xml文件中添加以下servlet配置
!-- H2 Database Console for managing the app's database --> H2Console org.h2.server.web.WebServlet -webAllowOthers true 2 H2Console /admin/h2/*
请查看更多详情https://github.com/spring-projects/greenhouse/blob/master/src/main/webapp/WEB-INF/web.xml
如果你的应用程序是基于spring boot而不是你必须遵循https://springframework.guru/using-the-h2-database-console-in-spring-boot-with-spring-security/