Spring Boot:无法登录H2控制台

时间:2020-09-09 07:16:59

标签: spring-boot h2

我是h2 DB的新手,我已经搜索了这个问题,但是没有找到解决方案。我想尝试使用Spring Boot构建一个TCP服务器模式,并让其他人使用Spring Boot或python将其连接。 这是我的以下财产:

autologinguests

我可以连接到localhost:8080 / h2-console,但无法登录,它会返回

db2.datasource.driverClassName=org.h2.Driver
db2.datasource.url=jdbc:h2:mem:testdb
db2.datasource.username=sa
db2.datasource.password=
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.jpa.hibernate.ddl-auto=update

我正在使用Spring Security,但是我的方法configure在开发人员模式下为空,我不知道应该在哪里修复...

我的pom.xml:

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Sep 09 15:08:13 CST 2020
There was an unexpected error (type=Forbidden, status=403).
Forbidden

和tcp服务器配置:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.4.200</version>
</dependency>

有人知道如何解决这个问题吗?

谢谢

2 个答案:

答案 0 :(得分:0)

好的,我发现了问题。 这是因为我正在使用Spring Security,并且是CSRF的自动启用保护,所以我扩展了WebSecurityConfigurerAdapter并覆盖了configure

@Override
protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.headers().frameOptions().disable();
    }

它成功运行。

答案 1 :(得分:0)

我认为您已经包含了Spring Security Starter。默认情况下,它将保护所有路径,请尝试在安全性配置中排除H2控制台路径( / h2-console )。