springboot requestMatchers 匹配 /**/** 的路由
时间: 2023-09-03 08:10:42 浏览: 65
`requestMatchers()` 方法用于添加 `RequestMatcher` 对象,以控制哪些请求应该由 `WebSecurityConfigurerAdapter` 处理。在 Spring Security 中,`/**/` 表示匹配任何路径,包括多级子路径。因此,如果您想让所有请求都被 `WebSecurityConfigurerAdapter` 处理,可以使用以下方式:
```java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
.antMatchers("/**/").permitAll() // 匹配任何路径
.anyRequest().authenticated()
.and()
.formLogin()
.and()
.httpBasic();
}
}
```
在上面的代码中,`antMatchers("/**/")` 用于匹配任何路径,而 `anyRequest().authenticated()` 用于保护所有其他请求。