为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Spring Security 启用 h2 控制台

使用 Spring Security 启用 h2 控制台

BIG阳 2023-05-17 14:49:09
我想在启用了 Spring Security 的 Spring Boot 项目中使用 h2-console。我的配置如下所示,但我无法访问任何未经身份验证的路径。如果我打开控制台路径,登录提示符就会出现。是不是顺序错了?我已经用 WebSecurityConfigurerAdapter 以旧方式尝试过它并且它有效,但我想使用新的东西。@EnableWebFluxSecuritypublic class SecurityConfiguration {    @Bean    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {        return http                .csrf().disable()                .headers().frameOptions().disable().and()                .authorizeExchange()                .anyExchange().permitAll()                .and()                .httpBasic().and()                .build();    }}我将配置更改为以下内容,并且身份验证像我预期的那样排除了 h2 控制台:@Configurationpublic class SecurityConfiguration extends WebSecurityConfigurerAdapter {    @Override    protected void configure(HttpSecurity http) throws Exception {        http.headers().frameOptions().disable().and()                .csrf().disable();        http                .authorizeRequests()                .antMatchers("/", "/h2-console/**").permitAll()                .anyRequest().authenticated()                .and()                .formLogin()                .permitAll()                .and()                .logout()                .permitAll();    }}
查看完整描述

1 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

H2 控制台似乎只能在基于 servlet 的服务器上使用,而 webflux 使用的码头不是基于 servlet 的服务器。

h2 无法访问


查看完整回答
反对 回复 2023-05-17
  • 1 回答
  • 0 关注
  • 139 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信