我想在啟用了 Spring Security 的 Spring Boot 項(xiàng)目中使用 h2-console。我的配置如下所示,但我無法訪問任何未經(jīng)身份驗(yàn)證的路徑。如果我打開控制臺(tái)路徑,登錄提示符就會(huì)出現(xiàn)。是不是順序錯(cuò)了?我已經(jīng)用 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(); }}我將配置更改為以下內(nèi)容,并且身份驗(yàn)證像我預(yù)期的那樣排除了 h2 控制臺(tái):@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貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
H2 控制臺(tái)似乎只能在基于 servlet 的服務(wù)器上使用,而 webflux 使用的碼頭不是基于 servlet 的服務(wù)器。
h2 無法訪問
添加回答
舉報(bào)
0/150
提交
取消