我在 Spring 引导应用程序中使用 H2 数据库。但是无法在 http://localhost:8080/console 的浏览器中打开它。我的 pom.xml 如下:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
</dependency>
弹簧启动配置:
Springboot配置文件
@Configuration
public class WebConfiguration {
@Bean
ServletRegistrationBean h2servletRegistration(){
ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
registrationBean.addUrlMappings("/console/*");
return registrationBean;
}
}
原文由 Bindumalini KK 发布,翻译遵循 CC BY-SA 4.0 许可协议
要使用 H2 控制台,您需要在
.properties
文件中对其进行配置其中
/h2console/
是您要在浏览器上使用的路径,因此您可以将其更改为任何内容。此外,如果您启用了安全性,您可能希望将其添加到允许的路径中还将此添加到您的
HttpSecurity
配置http.headers().frameOptions().disable();
编辑
更改您的安全配置我很确定您的 pom 中可能有 spring security 所以请改用它,如果没有它应该可以工作