更新时间:2022-02-24 09:00:22
这就是我如何让 H2 控制台在带有 H2 的 spring-boot 中工作.我不确定这是否正确,但由于没有其他人提供解决方案,因此我建议这是***的方法.
This is how I got the H2 console working in spring-boot with H2. I am not sure if this is right but since no one else has offered a solution then I am going to suggest this is the best way to do it.
就我而言,我为数据库选择了一个特定名称,以便在启动 H2 控制台时可以输入一些内容(在本例中为AZ").我认为所有这些都是必需的,尽管省略 spring.jpa.database-platform 似乎没有任何伤害.
In my case, I chose a specific name for the database so that I would have something to enter when starting the H2 console (in this case, "AZ"). I think all of these are required though it seems like leaving out the spring.jpa.database-platform does not hurt anything.
在 application.properties 中:
In application.properties:
spring.datasource.url=jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
在 Application.java(或一些配置)中:
In Application.java (or some configuration):
@Bean
public ServletRegistrationBean h2servletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
registration.addUrlMappings("/console/*");
return registration;
}
然后您可以在 {server}/console/访问 H2 控制台.输入它作为 JDBC URL:jdbc:h2:mem:AZ
Then you can access the H2 console at {server}/console/. Enter this as the JDBC URL: jdbc:h2:mem:AZ